Drawings SDK Developer Guide > Working with .dwg Files > Working with Databases > Working with Database Containers > Working with Predefined Tables of Named Records > Working with Specific Predefined Tables of Named Records > Linetypes Table > Manipulating of Linetypes > Getting and Checking Linetypes
Getting and Checking Linetypes

The linetype table object has the has() method for checking a linetype in the table and the getAt() method for getting an existing linetype from the table.

In the following examples, the pLinetypes variable stores a pointer to the linetype table object. The following example adds three linetypes in the table and deletes one of them:


OdDbLinetypeTableRecordPtr pLinetype;

pLinetype = OdDbLinetypeTableRecord::createObject();
pLinetype->setName("LinetypeX");
pLinetypes->add(pLinetype);

pLinetype = OdDbLinetypeTableRecord::createObject();
pLinetype->setName("ErasedLinetype");
pLinetypes->add(pLinetype);
pLinetype->erase(true);

pLinetype = OdDbLinetypeTableRecord::createObject();
pLinetype->setName("LinetypeY");
pLinetypes->add(pLinetype);

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


// Check the unerased linetype object by name
odPrintConsoleString(L"\nLinetype X %ls in the table", ((pLinetypes->has("LinetypeX")) ? L"exists" : L"absents"));

// Check the unerased linetype object by ID
odPrintConsoleString(L"\nLinetype Y %ls in the table", ((pLinetypes->has(pLinetype->objectId())) ? L"exists" : L"absents"));

// Check the erased linetype object (result is absent)
odPrintConsoleString(L"\nErased Linetype %ls in the table", ((pLinetypes->has("ErasedLinetype")) ? L"exists" : L"absents"));

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

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

  • The first argument is mandatory and specifies the linetype name as a nonempty OdString value that satisfies the requirements for naming objects.
  • The second argument is optional and specifies the open mode for the linetype 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 when the linetype table object must open an erased linetype record object or False when the linetype table object must open an unerased linetype record object. The value is False by default.

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


// Get the unerased linetype object in the read mode
OdDbLinetypeTableRecordPtr pLinetype1 = pLinetypes->getAt("LinetypeX");

// Get the unerased linetype object in the write mode
OdDbLinetypeTableRecordPtr pLinetype2 = pLinetypes->getAt("LinetypeY", OdDb::kForWrite, false);

// Get the unerased or erased linetype object in the notify mode
OdDbLinetypeTableRecordPtr pLinetype3 = pLinetypes->getAt("ErasedLinetype", OdDb::kForNotify, true);

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

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

To get the ID of a linetype 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 linetype object
OdDbObjectId idLinetype1 = pLinetypes->getAt("LinetypeX");

// Get the ID of the unerased linetype object
OdDbObjectId idLinetype2 = pLinetypes->getAt("LinetypeY", false);

// Get the ID of the erased linetype object
OdDbObjectId idLinetype3 = pLinetypes->getAt("ErasedLinetype", true);

To get a smart pointer to the linetype instance using an ID, use the safeOpenObject() method of the OdDbObjectId object, which opens the linetype record object associated with the specified ID in the specified mode for the specified erase status, and returns the smart pointer to it. For example:


// Get the unerased linetype object in the read mode using ID
OdDbLinetypeTableRecordPtr pLinetype1 = idLinetype1.safeOpenObject();

// Get the unerased linetype object in the write mode using ID
OdDbLinetypeTableRecordPtr pLinetype2 = idLinetype2.safeOpenObject(OdDb::kForWrite, false);

// Get the unerased or erased linetype object in the notify mode using ID
OdDbLinetypeTableRecordPtr pLinetype3 = idLinetype3.safeOpenObject(OdDb::kForNotify, true);

These operations can be combined in one line:


OdDbLinetypeTableRecordPtr pLinetype = pLinetypes->getAt("LinetypeY").safeOpenObject(OdDb::kForWrite);

When the erase status is False, the getAt() method gets the linetype record object if and only if it is marked as "unerased". When the erase status is True, the getAt() method gets the linetype 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 linetype with the specified name is absent from the linetype table, is permanently deleted, cannot be opened in the specified mode, or is marked as "erased" and the status argument is False. For example:


// When ID = kNull
OdDbObjectId idLinetype = pLinetypes->getAt("LinetypeN");
if(idLinetype.isNull())
  odPrintConsoleString(L"\nThe linetype N can not be opened\n");

// When Pointer = Null
OdDbLinetypeTableRecordPtr pLinetype = pLinetypes->getAt("LinetypeN", OdDb::kForWrite);
if(pLinetype.isNull())
  odPrintConsoleString(L"\nThe linetype N can not be opened\n");

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

See Also

Working with Linetypes

Adding and Naming Linetypes

Example of Working with the Linetype Table Object

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