Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Getting and Checking Registered Applications

The registered application table object has the has() method for checking an application in the table and the getAt() method for getting an existing application from the table. In the examples below, the pRegApps variable stores a pointer to the registered application table object. The following example adds three applications in the table and deletes one of them:


OdDbRegAppTableRecordPtr pRegApp;

pRegApp = OdDbRegAppTableRecord::createObject();
pRegApp->setName("RegAppX");
pRegApps->add(pRegApp);

pRegApp = OdDbRegAppTableRecord::createObject();
pRegApp->setName("ErasedRegApp");
pRegApps->add(pRegApp);
pRegApp->erase(true);

pRegApp = OdDbRegAppTableRecord::createObject();
pRegApp->setName("RegAppY");
pRegApps->add(pRegApp);

To check whether the application exists in the table, use the has() method of the registered application table object; it requires either the existing application name or the ID associated with the existing registered application record object as an argument of the method, and the method returns True if the application exists in the table or False if the application is absent from the table or is erased. For example:


// Check the unerased registered application object by name
odPrintConsoleString(L"\nRegApp X %ls in the table", ((pRegApps->has("RegAppX")) ? L"exists" : L"is absent"));

// Check the unerased registered application object by ID
odPrintConsoleString(L"\nRegApp Y %ls in the table", ((pRegApps->has(pRegApp->objectId())) ? L"exists" : L"is absent"));

// Check the erased registered application object (result is absent)
odPrintConsoleString(L"\nErased RegApp %ls in the table", ((pRegApps->has("ErasedRegApp")) ? L"exists" : L"is absent"));

To get an application from the registered application table, use the getAt() method of the registered application table object; it requires either the name or the ID of the registered application record object as a parameter for searching. The getAt() method has two implementations.

The first implementation of the getAt() method returns the smart pointer to the existing registered application record object that satisfies the specified parameters. The method has three arguments:

  • The first argument is mandatory and specifies the application name as a nonempty OdString value that satisfies the requirements for naming objects.
  • The second argument is optional and specifies the mode for opening the registered application record object as a value of the OdDb::OpenMode enumerator (kForRead, kForWrite, or kForNotify). The value is OdDb::kForRead by default.
  • The third argument is optional and specifies the erase status as a Boolean value which is True if the registered application table object must open an erased registered application record object or False when the registered application table object must open an unerased registered application record object. The value is False by default.

To get a smart pointer to the registered application record object, declare a variable of the OdDbRegAppTableRecordPtr type and use the first implementation of the getAt() method. For example:


// Get the unerased registered application object in the read mode
OdDbRegAppTableRecordPtr pRegApp1 = pRegApps->getAt("RegAppX");

// Get the unerased registered application object in the write mode
OdDbRegAppTableRecordPtr pRegApp2 = pRegApps->getAt("RegAppY", OdDb::kForWrite, false);

// Get the unerased or erased registered application object in the notify mode
OdDbRegAppTableRecordPtr pRegApp3 = pRegApps->getAt("ErasedRegApp", OdDb::kForNotify, true);

The second implementation of the getAt() method returns the OdDbObjectId instance associated with the registered application record object that satisfies the specified name. The method has two arguments:

  • The first argument is mandatory and specifies the application name as a nonempty OdString value.
  • The second argument is optional, specifies the erase status as a Boolean value, and is False by default.

To get the ID of the registered application record object, declare a variable of the OdDbObjectId type and use the second implementation of the getAt() method. For example:


// Get the ID of the unerased registered application object
OdDbObjectId idRegApp1 = pRegApps->getAt("RegAppX");

// Get the ID of the unerased registered application object
OdDbObjectId idRegApp2 = pRegApps->getAt("RegAppY", false);

// Get the ID of the erased registered application object
OdDbObjectId idRegApp3 = pRegApps->getAt("ErasedRegApp", true);

To get the smart pointer to the registered application instance with matching ID, use the safeOpenObject() method of the OdDbObjectId object to open the registered application record object associated with the specified ID in the specified mode for the specified erase status, and return the a smart pointer to it. For example:


// Get the unerased registered application object in the read mode using ID
OdDbRegAppTableRecordPtr pRegApp1 = idRegApp1.safeOpenObject();

// Get the unerased registered application object in the write mode using ID
OdDbRegAppTableRecordPtr pRegApp2 = idRegApp2.safeOpenObject(OdDb::kForWrite, false);

// Get the unerased or erased registered application object in the notify mode using ID
OdDbRegAppTableRecordPtr pRegApp3 = idRegApp3.safeOpenObject(OdDb::kForNotify, true);

These operations can be combined into one line:


OdDbRegAppTableRecordPtr pRegApp = pRegApps->getAt("RegAppY").safeOpenObject(OdDb::kForWrite);

When the erase status is False, the getAt() method gets the registered application record object if and only if it is marked as "unerased". When the erase status is True, the getAt() method gets the registered application record object of any status, that is, marked as "erased" or "unerased".

The getAt() method returns the ID = kNull or smart pointer = Null when the application with the specified name is absent from the table, is permanently deleted, not opened in the specified mode, or marked as "erased" and the status argument is False. For example:


// When ID = kNull
OdDbObjectId idRegApp = pRegApps->getAt("RegAppN");
if(idRegApp.isNull())
  odPrintConsoleString(L"\nThe registered application N can not be opened\n");

// When Pointer = Null
OdDbRegAppTableRecordPtr pRegApp = pRegApps->getAt("RegAppN", OdDb::kForWrite);
if(pRegApp.isNull())
  odPrintConsoleString(L"\nThe registered application N can not be opened\n");

Before getting a registered application, use the has() method for checking whether the application with the specified name exists in the table.

See Also

Working with Registered Applications

Adding and Naming Registered Applications

Example of Working with the Registered Application Table Object

Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.