Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Organization of Layouts

The database stores all layouts in a layout dictionary, where each layout is an item of the layout dictionary. The layout dictionary is a standard dictionary object of the database that is placed in the root drawing dictionary and has the common dictionary interface for manipulating the stored layouts. The "ACAD_LAYOUT" keyword identifies the layout dictionary object in the root.

The OdDbLayout class is the layout object that represents the interface for accessing a layout and manipulating its properties. The OdDbDictionary class is used as a container for storing layouts. A layout object has the AcDbLayout class name, and a layout dictionary object has the AcDbDictionary class name.

The OdDbLayoutPtr class is the typified smart pointer to an instance of the layout and is used for storing and passing references to the layout object. In the following examples, the pDb variable stores a pointer to the database object.

To get the layout dictionary, use the getLayoutDictionaryId() method of the database object which has one argument — the preset status as a Boolean value — and returns the OdDbObjectId instance associated with the layout dictionary object. The layout dictionary is preset object in a database, so the argument is not required (it is True by default). For example:


OdDbObjectId idLayouts = pDb->getLayoutDictionaryId();

To get the layout dictionary ID, you can also use the root drawing dictionary. For example:


OdDbDictionaryPtr pRoot = pDb->getNamedObjectsDictionaryId().safeOpenObject();

OdDbObjectId idLayouts = pRoot->getAt(L"ACAD_LAYOUT");

if(!idLayouts.isNull())
  odPrintConsoleString(L"\nThe layout's dictionary has ID = %s\n", idLayouts.getHandle().ascii().c_str());

To manipulate layouts, the program must open the layout dictionary object and get a smart pointer to it. If the layout is opened in read mode, the program can obtain the layout objects. If the layout is opened in write mode, the program can add a new layout in the dictionary, rename any layout, or delete the layout from the dictionary.

To get the smart pointer to the layout dictionary object, declare a variable of the OdDbDictionaryPtr type and use the safeOpenObject() method of the obtained OdDbObjectId object. This method requires one argument — the mode to be opened as a value of the OdDb::OpenMode enumerator (kForRead, kForWrite, or kForNotify) — and returns a smart pointer to the object. For example:


// Open the layout's dictionary in the read mode
OdDbDictionaryPtr pLayouts = idLayouts.safeOpenObject(OdDb::kForRead);

// Open the layout's dictionary in the write mode
OdDbDictionaryPtr pLayouts = idLayouts.safeOpenObject(OdDb::kForWrite);

These operations can be united in one line:


OdDbDictionaryPtr pLayouts = pDb->getLayoutDictionaryId(true).safeOpenObject(OdDb::kForWrite);

The database contains two predefined layouts — the layout associated with model space and the layout associated with paper space. The first predefined layout has the fixed name "Model" and is always associated with the predefined block record object "*Model_Space", assigned as the model space of the database. The second predefined layout can have an arbitrary name and is associated with the block record object "*Paper_Space", assigned as the paper space of the database. The database can switch between multiple paper layouts and can assign another block record object associated with a paper layout as paper space (for more details, see Concept of Layouts).

To get the model space block, use the the getModelSpaceId() method of the database object. To get the paper space block, use the the getPaperSpaceId() method of the database object. These methods return the object ID of blocks. The model space and paper space blocks are associated with corresponding layouts — model and paper. To get the layout, use the getLayoutId() method of the block record object. For example:


OdDbBlockTableRecordPtr pModelSpace = pDb->getModelSpaceId().safeOpenObject();
OdDbBlockTableRecordPtr pPaperSpace = pDb->getPaperSpaceId().safeOpenObject();

OdDbLayoutPtr pModelLayout = pModelSpace->getLayoutId().safeOpenObject();
OdDbLayoutPtr pPaperLayout = pPaperSpace->getLayoutId().safeOpenObject();

odPrintConsoleString(L"\nModel space block: \"%s\" and model layout: \"%s\"\n", 
                     pModelSpace->getName().c_str(), pModelLayout->getLayoutName());
odPrintConsoleString(L"\npaperspace block: \"%s\" and paper layout: \"%s\"\n", 
                     pPaperSpace->getName().c_str(), pPaperLayout->getLayoutName());

The layout dictionary has the standard dictionary interface for manipulating layout objects.

See Also

Working with Layouts

Concept of Layouts

Associations of the Layout Object

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