Drawings SDK Developer Guide > Working with .dwg Files > Working with Databases > Working with Database Containers > Working with Dictionaries of Objects > Working with Specific Dictionaries > Multi-Line Styles Dictionary > Making a Multi-Line Style Active
Making a Multi-Line Style Active

A single multi-line style in the dictionary can be the current active style. The current active multi-line style is the object that is associated by default with a new multi-line entity; it is added in the database if the setDatabaseDefaults() function is called. The multi-line entity has the style() and setStyle() methods for associating it with a multi-line style object, which defines its appearance. When the program creates a new multi-line entity and adds it in the database, it gets the current active multi-line style as a default object to set the association.

The CMLSTYLE system variable stores the object ID of the current active multi-line style. This variable is set to the "Standard" predefined multi-line style in the database by default. The database object provides the ability to access the system variables using get#() and set#() methods, where # is the variable name. In the following examples, the pMLStyle variable stores a pointer to the multi-line style object, the pMLine variable stores a pointer to the multi-line entity, and the pDb variable stores a pointer to the database object. For example:


// Get the database object from the multi-line style object
OdDbDatabasePtr pDb = pMLStyle->database();

// Get the database object from the multi-line entity
OdDbDatabasePtr pDb = pMLine->database();

To get the current active multi-line style, use the getCMLSTYLE() method of the database object that does not have arguments and returns the OdDbObjectId instance associated with the current active multi-line style object. For example:


// Get the ID of the current active multi-line style
OdDbObjectId idActive = pDb->getCMLSTYLE();

To get the smart pointer to it, declare a variable of the OdDbMlineStylePtr type and use the safeOpenObject() method of the obtained OdDbObjectId object in the corresponding open mode (kForRead, kForWrite, or kForNotify). For example:


// Open the current active multi-line style in the read mode
OdDbMlineStylePtr pMLSActive = idActive.safeOpenObject(OdDb::kForRead);

// Open the current active multi-line style in the write mode
OdDbMlineStylePtr pMLSActive = idActive.safeOpenObject(OdDb::kForWrite);

These operations can be united in one line:


OdDbMlineStylePtr pMLSActive = pMLine->database()->getCMLSTYLE().safeOpenObject();
odPrintConsoleString(L"\nActive multi-line style: \"%s\"\n", pMLSActive->getName().c_str());

To make a multi-line style active, use the setCMLSTYLE() method of the database object that requires the object ID of the multi-line style object to be set active as an argument of the OdDbObjectId type and does not return a value. For example:


OdDbMlineStylePtr pMLStyle = OdDbMlineStyle::createObject();
OdDbDictionaryPtr pMLStyles = pDb->getMLStyleDictionaryId(true).safeOpenObject(OdDb::kForWrite);
pMLStyle->setName(L"Style");
OdDbObjectId idMLStyle = pMLStyles->setAt(L"Style", pMLStyle);

pDb->setCMLSTYLE(idLinetype);     // or //    pDb->setCMLSTYLE(pMLStyle->objectId());

If another multi-line style becomes the current active multi-line style, multi-line entities associated with the previous active multi-line style save their own associations. Changing of the current active multi-line style influences only new multi-line entities.

Additionally, the database has the CMLJUST system variable that stores the default justification and the CMLSCALE system variable that stores the default scale factor for a new multi-line entity. These variables have the same interface. For example:


odPrintConsoleString(L"\nActive scale factor = %g\n", pDb->getCMLSCALE());
odPrintConsoleString(L"\nActive justification = %d\n", pDb->getCMLJUST());

pDb->setCMLJUST(0);
pDb->setCMLSCALE(2.5);

See Also

Working with Multi-Line Styles

Example of Working with the Multi-Line Style Dictionary

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