A layout in the layout dictionary of the database can be currently active. The current active layout is immediately accessed when the database is opened. The database object provides working with the active layout through specific methods of the database object and through system variables. In the following examples, the pDb variable stores a pointer to the database object, and the pLayout variable stores a pointer to the layout object.
To get the current active layout, use the currentLayoutId() method of the database object which returns the ID of current active layout object as an instance of the OdDbObjectId type. For example:
OdDbObjectId idActive = pDb->currentLayoutId();
To work with properties of the current active layout, declare a variable of the OdDbLayoutPtr type and use the safeOpenObject() method of the object ID to get a smart pointer to the layout. The current active layout cannot be erased, but it can be modified using any mode. Continuing the example:
OdDbLayoutPtr pLayout = idActive.safeOpenObject(OdDb::kForRead);
odPrintConsoleString(L"\nCurrent active layout \"%s\" (tab=%d) %s", pLayout->getLayoutName().c_str(),
pLayout->getTabOrder(), ((pLayout->modelType()) ? L"Model" : L"Paper"));
To make a layout currently active, use the setCurrentLayout() of the database object which requires one argument — either the ID as an instance of the OdDbObjectId type or the name as an instance of the OdString type of an existing layout object to be set active — and does not return a value. For example:
// Make active layout by name
pDb->setCurrentLayout(L"Model");
// Make active layout by ID
OdDbObjectId idLayout = pDb->createLayout(L"Sheet A-A");
pDb->setCurrentLayout(idLayout);
Alternative, the CTAB system variable stores an ID of the current active layout object. To get the current active layout, use the getSysVar() method which requires the variable name as an argument of the OdString type and returns an instance of OdResBufPtr type. To get the object ID from the resbuf-instance, use its getObjectId() method, which requires a pointer to the database as an argument and returns an instance of the OdDbObjectId type associated with the active layout. For example:
OdRusBufPtr pRb = pDb->getSysVar(L"CTAB");
OdDbObjectId idCTab = pRb->getObjectId(pDb);
OdDbLayoutPtr pLayout = idCTab.safeOpenObject(OdDb::kForRead);
odPrintConsoleString(L"\nCurrent active layout \"%s\" (tab=%d) %s", pLayout->getLayoutName().c_str(),
pLayout->getTabOrder(), ((pLayout->modelType()) ? L"Model" : L"Paper"));
To set the current active layout, use the setSysVar() method which requires the resbuf-instance as an argument. The resbuf-type should be set to the kRtEntName value. For example:
OdDbObjectId idLayout = pDb->createLayout(L"Sheet A-A");
OdRusBufPtr pRb = OdResBuf::newRb();
pRb->setRestype(OdResBuf::kRtEntName);
pRb->setObjectId(idLayout);
pDb->setSysVar(L"CTAB", pRb);
The active layout is associated with the block record object. Thus, the block associated with the active layout becomes also active and can be obtained through the database object. To get the active block table record object (BTR), use the getActiveLayoutBTRId() method of the database object which returns the ID of the associated block as an instance of the OdDbObjectId type. For example:
OdDbObjectId idActBTR = pDb->getActiveLayoutBTRId();
OdDbLayoutPtr pBlock = idActBTR.safeOpenObject(OdDb::kForRead);
odPrintConsoleString(L"\nCurrent active block %s-\"%s\"", pBlock->handle().ascii().c_str(), pBlock->getName().c_str());
The active layout can be model type or paper type. The TILEMODE system variable determines the type of the current active layout. This variable returns True if the active layout is the model type, or False if the active layout is the paper type.
To check the type of the current active layout, use the getTILEMODE() method of the database object which returns the type as a Boolean value. For example:
odPrintConsoleString(L"\nCurrent active tab is ", (pDb->getTILEMODE() ? L"model" : L"paper"));
To switch the type of the current active layout, use the setTILEMODE() method of the database object which requires a Boolean value. When the value is True, this method makes active the model layout associated with the model space block table record (*Model_space"). When the value is False, this method makes active only one of the paper layouts that is associated with the paper space block table record (*Paper_space"). For example:
// Make the model layout active
pDb->setTILEMODE(true);
// Make the paper layout active
pDb->setTILEMODE(false);
Note: The TILEMODE system variable can be used for checking the current active layout and associated block when the database is created or opened.
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|