Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Making a Linetype Active

One of the linetypes in the linetype table of the database can be the current active linetype. The current active linetype is the object that is automatically associated with any new entity that is added in the database. Each entity must have a linetype to be drawn. An entity has the linetype() method that returns the name of the associated linetype, the linetypeId() method that returns the ID of the associated linetype record object, and the setLinetype() method that sets the linetype for the entity. If the linetype property is set to ByLayer, the entity uses the linetype of the layer to which it belongs. If the linetype property is set to ByBlock, the entity uses the linetype of the block in which it is a part. When the program creates an entity and adds it in the database, the new entity gets the current active linetype by default.

The CELTYPE system variable stores the object ID of the current active linetype. This variable is set to one of the predefined linetypes by default: ByLayer, ByBlock, or Continuous, but the program can set any available linetype to be the current active linetype after creating the database. The database object provides access to system variables using get#() and set#() methods, where # is the variable name. The program can obtain the database object either from the host application object or linetype table object.

In the examples below, the pLinetypes variable stores a pointer to the linetype table object and the pHost variable stores a pointer to the host application object. For example:


// Create the database object using the host application object
OdDbDatabasePtr pDb = pHost->createDatabase();

// Get the database object from the linetype table object
OdDbDatabasePtr pDb = pLinetypes->database();

To get the current active linetype, use the getCELTYPE() of the database object that does not have arguments and returns the OdDbObjectId instance associated with the current active linetype record object. For example:


// Get the ID of the current active linetype
OdDbObjectId idActiveLinetype = pDb->getCELTYPE();

To get a smart pointer to the current active linetype, declare a variable of the OdDbLinetypeTableRecordPtr type and use the safeOpenObject() method of the obtained OdDbObjectId object. The current active linetype cannot be erased, therefore the safeOpenObject() method requires only the open mode of the OdDb::OpenMode type (kForRead, kForWrite, or kForNotify). For example:


// Open the current active linetype in the read mode
OdDbLinetypeTableRecordPtr pActiveLinetype = idActiveLinetype.safeOpenObject(OdDb::kForRead);

// Open the current active linetype in the write mode
OdDbLinetypeTableRecordPtr pActiveLinetype = idActiveLinetype.safeOpenObject(OdDb::kForWrite);

These operations can be combined in one line:


OdDbLinetypeTableRecordPtr pActiveLinetype = pLinetypes->database()->getCELTYPE().safeOpenObject();
odPrintConsoleString(L"\n\nCurrent active linetype: \"%ls\"\n", pActiveLinetype->getName().c_str());

To make a linetype active, use the setCELTYPE() of the database object; it requires the ID of the linetype record object to be set active as an argument of the OdDbObjectId type and does not return a value. For example:


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

pDb->setCELTYPE(idLinetype);

To get the ID of the linetype record object that has the pointer, use the objectId() method of the linetype record object that returns the OdDbObjectId instance associated with this linetype. For example:


OdDbLinetypeTableRecordPtr pLinetype = pLinetypes->getAt("LinetypeX", OdDb::kForWrite, false);
pDb->setCELTYPE(pLinetype->objectId());

If another linetype becomes the current active linetype, entities associated with the previous active linetype do not change; their association with the previous linetype is saved. Changing the current active linetype influences only new entities.

Note: The current active linetype cannot be deleted. Change the active linetype before deleting.

See Also

Working with Linetypes

Getting and Checking Linetypes

Example of Working with the Linetype Table Object

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