Perform Simple Editing and Saving of Autodesk® Navisworks® Files

Vadim Asandiy

July 10, 2020

NWF format files are represented in a BimNv database as an OdNwDatabase object with a container of pointers to OdNwModel objects. Each OdNwModel object contains information about models from an .nwf file:

  • Path to the file
  • Transformation matrix
  • Linear units
  • Etc.

More detailed information can be obtained from the public API of the OdNwModel class described at docs.opendesign.com (login required).

You can use the example below from the OdNwfResaver project located in Examples/OdNwfResaver/OdNwfResaver.cpp to:

  • Create an OdNwDatabase object.
  • Change the transformation matrix of a model.
  • Change the linear units of a model.
  • Add a new model to the current list of .nwf models.

Create an OdNwDatabase Object

Create an OdNwDatabase object corresponding to the .nwf file:


	 //need to read file by path from szSource
OdNwDatabasePtr pNwDb = svcs.readFile(szSource);

Next, make sure that the OdNwDatabase object contains NWF; for this format, the OdNwDatabase::isComposite method returns true:

if (pNwDb->isComposite())

To change properties of the model, get the object from the database. For this, use the OdNwDatabase::getModels method; if successful, OdNwDatabase::getModels method returns eOk:

OdArray<OdNwModelPtr> m_aModels;
if (pNwDb->getModels(m_aModels) == eOk)

Select the desired model, for example, according to a known index:

pCurrentModel = m_aModels[modelIndex]

Change the Transformation Matrix of the Model

To change the matrix, call the OdNwModel::setTransform method with the OdGeMatrix3d object as a parameter (in OdNwfResaver, an identity matrix is passed, but you can get the matrix object using the OdNwModel::getTransform method too). Perform the desired transformations on it and pass it as a parameter:

pCurrentModel->setTransform(OdGeMatrix3d::kIdentity);

Change Linear Units of the Model

To change the units, call the OdNwModel::setUnits method with the NwModelUnits::Enum object as a parameter:

pCurrentModel->setUnits(NwModelUnits::UNITS_METERS);

Add a New Model to the Current List of NWF Models

To add a model, call the OdNwDatabase::addModel method, into which you must pass a pointer to a pre-created OdNwModel object as a parameter. The OdNwModel object must contain a non-empty file path value (currently you can add these format files: .dwg, .dgn, .rfa /.rvt, .nwc/.nwd):

pCurrentModel = OdRxObjectImpl<OdNwModel>::createObject();
if (pCurrentModel->setSourcePath(path) == eOk)
{
  if (pNwDb->addModel(pCurrentModel) == eOk)