COM API: Apply a saved viewpoint within a folder

By Xiaodong Liang

 

Before Navisworks 2013, we need to use COM API to access viewpoint and saved viewpoint. The state object provides SavedViews which is the collection of the saved viewpoints.  Some more relevant objects:

InwOpSavedView: the parent object of the explicit saved view (InwOpView), or folder view (InwFolderview) or animation view (InwOpAnimView), or animation cut (InwOpCutView).

a folder view could contain any types saved views, even sub folder.

an animation view can also contain other type of saved views. But typically, it contains the series of InwOpView or InwOpAnimView.

The enum nwESavedViewType defines which type of subclass an InwOpSavedView is.

eSavedViewType_View
InwOpView.

eSavedViewType_Anim
InwOpAnimView.

eSavedViewType_Cut
InwOpCutView.

eSavedViewType_Folder
InwOpFolderView.

 

image

 

//dump the info of the InwOpView    void Info_SaveView(ComApi.InwOpView  savedview)    {        string viewname = savedview.name;        ComApi.InwOpAnonView oAnoView = savedview.anonview;        ComApi.InwNvViewPoint oViewPoint = oAnoView.ViewPoint;        ComApi.InwNvCamera oCamera = oViewPoint.Camera;    }         // recurse the folder/animation view    void recurseGroupView(ComApi.InwOpGroupView parentSavedView)                                 {        foreach (ComApi.InwOpSavedView savedview in             parentSavedView.SavedViews())        {            if (savedview.Type ==                 ComApi.nwESavedViewType.eSavedViewType_View)            {                Info_SaveView((ComApi.InwOpView)savedview);            }            else if (savedview.Type ==                 ComApi.nwESavedViewType.eSavedViewType_Folder)            {                          // recurse the folder                ComApi.InwOpFolderView oFolderView =                    (ComApi.InwOpFolderView)parentSavedView;                recurseGroupView(oFolderView);             }            else if (savedview.Type ==                ComApi.nwESavedViewType.eSavedViewT
ype_Anim)            {                // recurse the animation                ComApi.InwOpAnimView oAnimationView =                    (ComApi.InwOpAnimView)parentSavedView;                recurseGroupView(oAnimationView);            }            else if (savedview.Type ==                 ComApi.nwESavedViewType.eSavedViewType_Cut)            {                //                ComApi.InwOpCutView oCutView =                     (ComApi.InwOpCutView)savedview;                               }            else            {                MessageBox.Show("error!");            }        }         }              // iterate the saved views of the document    void DumpSavedView_COMAPI()    {        ComApi.InwOpState10 oState;        oState = ComBridge.State;             foreach (ComApi.InwOpSavedView savedview            in oState.SavedViews())        {            if (savedview.Type ==                 ComApi.nwESavedViewType.eSavedViewType_View)            {                Info_SaveView((ComApi.InwOpView)savedview);            }            else if (savedview.Type ==                 ComApi.nwESavedViewType.eSavedViewType_Folder)            {                                 // recurse the folder                ComApi.InwOpFolderView                    oFolderView = (ComApi.InwOpFolderView)savedview;                recurseGroupView(oFolderView);            }            else if (savedview.Type ==                ComApi.nwESavedViewType.eSavedViewType_Anim)            {                // recurse the animation                ComApi.InwOpAnimView oAnimationView =                     (ComApi.InwOpAnimView)savedview;                recurseGroupView(oAnimationView);            }            else if (savedview.Type ==                 ComApi.nwESavedViewType.eSavedViewType_Cut)            {                                ComApi.InwOpCutView oCutView =                     ComApi.InwOpCutView)savedview;              }            else            {                MessageBox.Show("error!");            }        }               }

To set an saved view to the current view, the code could be:

// assume we got an InwOpView from the saved view    //ComApi.InwOpView savedview;     // apply it to the current view    oState.ApplyView(savedview);

Comments

7 responses to “COM API: Apply a saved viewpoint within a folder”

  1. Hello!
    This is parts of code working with all savedpoints, but if i need to get collection of selected viewpoints?
    can i do that?
    i can get only one currentSelected viewpoint (last, if is multiselection).
    i think i cant get it by NET, maybe COM can help?
    Thanks.

  2. Xiaodong Liang Avatar
    Xiaodong Liang

    hello,
    there is no API in COM to know the current selected saved viewpoint. In 2013 .NET API, you can get it by DocumentSavedViewpoints.CurrentSavedViewpoint
    Regards,
    Xiaodong

  3. Xiaodong Liang Avatar
    Xiaodong Liang

    hello,
    there is no API in COM to know the current selected saved viewpoint. In 2013 .NET API, you can get it by DocumentSavedViewpoints.CurrentSavedViewpoint
    Regards,
    Xiaodong

  4. Thanks for reply!
    But if i have multiselection and use Document.SavedViewpoints.CurrentSavedViewpoint get only last selected viewpoint. But i need get all selected viewpoints..comthing like colliction of selected viewpoints. Can i do this?
    for example:
    Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;
    foreach (SavedItem si in oDoc.SavedViewpoints.Value)
    {
    MessageBox.Show(oDoc.SavedViewpoints.CurrentSavedViewpoint.DisplayName);
    }
    if i selected 4 viewpoints, the result is one messagebox with last selected display name.
    Best Regards,
    Sergey

  5. Xiaodong Liang Avatar
    Xiaodong Liang

    Hi Sergey,
    yes, CurrentSavedViewpoint tells the last selected view points only. Can I know why you want to know the multi-selected items? As I know, only one saved viewpoint can be applied to the current view.
    If what you wanted is to do some post work after the user multi-selected the viewpoints, I would suggest you create your own panel to manage the viewpoints. Thus you can know multi-selected easily.
    Regards,
    Xiaodong

  6. Hello, Xiaodong!
    I need get multiselected items for package renaming of viewpoints.
    Am already maked a dock panel with a my own views, but its not rigth for me.
    Well thx for answers.
    P.S.: Very usefull blog. i am glad that i founded it)

  7. Can we create animations through Navisworks API ?

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading