ODA BimNv SDK: Save Viewpoints

Vadim Asandiy

May 11, 2023

To access saved viewpoints in NWD/NWC files, use the method OdResult OdNwDatabase::getSavedViewsElements(OdNwObjectIdArray& aSavedViewsElementIds) const:

//…
OdNwDatabasePtr pDb;
//…
OdNwObjectIdArray aSavedViewElements;
if (pDb->getSavedViewsElements(aSavedViewElements) == eOk)
//…

 

All of these objects are derived from the OdNwSavedItem class:

//…
for (OdInt32 i = 0; i < aSavedViewElements.size(); i++)
{
OdNwSavedItemPtr pSI = aSavedViewElements[i].openObject();
//…

 

Each saved item has a common property set:

//…
OdArray<OdNwComment> aComments = pSI->getCommentCollection();
for (OdInt32 i = 0; i < aComments.size(); i++)
{
  OdNwComment& comment = aComments[i];
  //comment author
  OdString sAuthor = comment.getAuthor();
  //comment's content
  OdString sBody = comment.getBody();
  //when this comment was created
  tm createDate = comment.getCreateDate();
  //is this comment – new, active, approved or resolved
  NwCommentStatus::Enum status = comment.getStatus();
}
OdString sSIName = pSI->getDisplayName();
OdGUID guidSI = pSI->getGuID();
OdNwObjectId parentId = pSI->getParentId();
//…
  • Comment list — Get by using the method OdArray<OdNwComment> getCommentCollection() const.
  • Saved item's name — Get by using the method OdString getDisplayName() const..
  • Global GUID — Get by using the method OdGUID getGuID() const.
  • Parent of current item — Get by using the method OdNwObjectId getParentId() const, which accesses the hierarchy of the saved item's root tree structure.

 

Saved viewpoints can be any of the following:

  • Folder item, which contains nested saved items as children:
    //…
    if (pSI->isA() == OdNwSavedFolderItem::desc())
    {
    OdNwSavedFolderItemPtr pFolder = OdNwSavedFolderItem::cast(pSI);
    OdNwObjectIdArray aChildren;
    if (pFolder->getChildren(aChildren) == eOk)
    {
      for (OdInt32 i = 0; i < aChildren.size(); i++)
      {
        OdNwSavedItem pChildSI = aChildren[i].openObject();
        //…
      }
    //…
  • One frame cut from an animation:
    //…
    if (pSI->isA() == OdNwSavedViewpointAnimationCut::desc())
    {
      OdNwSavedViewpointAnimationCutPtr pAnimCut = OdNwSavedViewpointAnimationCut::cast(pSI);
      double cutDelay = pAnimCut-> getDelay();
    }
    //…
  • An animation, which can contain nested saved items as children:
    //…
    if (pSI->isA() == OdNwSavedViewpointAnimation::desc())
    {
    OdNwSavedViewpointAnimationPtr pAnim = OdNwSavedViewpointAnimation::cast(pSI);
    OdInt32 loopPlayback = pAnim->getLoopPlayback();
    NwAnimationSmoothing::Enum smoothing = pAnim->getSmoothing();
    OdNwObjectIdArray aChildren;
    if (pAnim->getChildren(aChildren) == eOk)
    {
    for (OdInt32 i = 0; i < aChildren.size(); i++)
    {
      OdNwSavedItem pChildSI = aChildren[i].openObject();
      //…
    }
    //…
  • Retrieved saved viewpoints with parameters, cutting plains, redline data, and override appearance information:
    //…
    if (pSI->isA() == OdNwSavedViewpoint::desc())
    {
      OdNwSavedViewpointPtr pSavedViewpoint = OdNwSavedViewpoint::cast(pSI);
      // get viewpoint
      OdNwViewpoint pView = pSavedViewpoint->getViewpointId().openObject();
      // get section data
      OdNwClipPlaneSetPtr pClipPlane = pSavedViewpoint->getClippingPlanesId().openObject();
      // get redline data if saved viewpoints has
      OdNwObjectIdArray aRedLines;
      pSavedViewpoint->getRedLineList(aRedLines);
      // get override appearance info for this saved viewpoint
      OdNwObjectIdArray aHiddensMIs;
      pSavedViewpoint->getHiddens(aHiddensMIs);
      OdNwObjectIdArray aRequiredsMIs;
      pSavedViewpoint->getRequireds (aRequiredsMIs);
      OdUInt32 cntOfAppearanceOverride = pSavedViewpoint->getAppearanceOverrideCount();
      OdNwObjectIdArray aOverrideAppearanceMIs;
      OdNwObjectId matId;
      pSavedViewpoint->getAppearanceOverride(0, aOverrideAppearanceMIs, matId);
    }
    //…

 

Example code that shows how to work with saved viewpoints can be found in the Nw2Visualize plugin source code.

For example, to import saved viewpoints from an NWD file:

  1. Run OdVisualizeViewer and when opening an NWD/NWC file, mark Import Saved Viewpoints


     
  2. All saved viewpoints without redlines are imported as TvCamera objects to Database > Models > Service Models > Model <$ODA_TVVIEWER_SAVEDVIEWS>.



  3. Here is the saved viewpoint hierarchy from Autodesk® Navisworks®:

  4. To set a saved viewpoint as the active view, select the needed camera in the Visualize Object Explorer and assign it as the active view from the properties window:


  5. See the comparison of views in Navisworks and OdVisualizeViewer:
    • internals

      View in Navisworks View in OdVisualizeViewer

    • rear drive
      View in Navisworks View in OdVisualizeViewer

    • overview

 Find out more in our documentation: https://docs.opendesign.com/bimnv/bimnv_saving_viewpoints.html