BimNv SDK: Work with a Database that has Multiple Sheets

Vadim Asandiy

February 18, 2022

You can work with .nwd, .nwc, and .nwf files that contain more than one sheet. Working with sheets is similar to working with several files that are unrelated to each other, but with the changes saved in one place. This section explains the basics of working with sheets.

To get information about existing sheets in a file, read the .nwd, .nwc or .nwf file database:

OdString szSource;//path to file
OdNwDatabasePtr pDb = svcs.readFile(szSource);

After opening the file, the database has a currently active sheet which is the sheet that was saved as active in the file. If the file contains only one sheet, this sheet is active after opening the file. To get the currently active sheet, use the method OdNwObjectId getActiveSheetId() const:

OdNwObjectId activeSheetId = pDb->getActiveSheetId();
OdNwSheetInfoPtr pActiveSheet = activeSheetId.openObject();

To get the list of sheets that exist in a file, use the method OdResult OdNwDatabase::getSheets(OdNwObjectIdArray& aSheets) const:

OdNwObjectIdArray aSheets;
pDb->getSheets(aSheets);

Each element of the aSheets array is an OdNwObjectId element of a sheet object. For example, to get data for the sheet with index 1:

//Required index must be in the range of the array, otherwise an exception is thrown.
OdNwSheetInfoPtr pSheet = aSheets[1].openObject();
//Get the type of the sheet: 2D or 3D
NwSheetType::Enum sheetType = pSheet->getSheetType();
//Get the ID of the selected sheet info object
OdString newSheetId = pSheet->getSheetId();

To make the selected sheet active in the database, use the method OdResult OdNwDatabase::setActiveSheet(const OdString& sheetId), specifying the sheet ID:

pDb->setActiveSheet(newSheetId);

Once the sheet is set to the active state, the database points to that current sheet. Use the following methods to get data from the current sheet:

  • OdNwObjectId OdNwDatabase::getCurrentViewId() const;
  • OdNwObjectId OdNwDatabase::getCurrrentViewClippingPlanesId() const;
  • OdResult OdNwDatabase::getSavedViewsElements(OdNwObjectIdArray& aSavedViewsElementIds) const;
  • OdNwObjectId OdNwDatabase::getBackgroundElementId() const;
  • OdNwObjectId OdNwDatabase::getClashElementId() const;
  • OdResult OdNwDatabase::getModels(OdNwObjectIdArray& arrModels) const;
  • OdNwObjectId OdNwDatabase::getModelItemRootId() const;
  • OdGeMatrix3d OdNwDatabase::getModelTransform() const;
  • NwModelUnits::Enum OdNwDatabase::getUnits() const;
  • OdResult OdNwDatabase::getLightElements(OdNwObjectIdArray& arrLights) const;
  • OdNwGridSystemElementPtr OdNwDatabase::getGridSystemElement() const;
  • OdNwObjectId OdNwDatabase::getSelectionSetsElementId() const;
  • OdNwObjectId OdNwDatabase::getSavedAnimationElementId() const;

For .nwf files you can also add a model to the currently active sheet using the method OdNwObjectId OdNwDatabase::addModel(const OdString& sourcePath, OdResult* pResCode = NULL);.