Create New Saved Viewpoint in Javascript

By Xiaodong Liang

The process to create a saved viewpoint in COM API is:

  1. make a copy of the current view. It is the anonymous viewpoint.
    2. create a new object with the type InwOpView
    3. attach the anonymous viewpoint to the new view.
    4. add the new view to the saved viewpoints collection

The codes below demonstrates the process. it also shows how to switch to the new view.

function createView1()

{

    //assume nwviewer is the object of ActiveX control.

    var state = nwviewer.state;

    var savedviewscount =

        state.SavedViews().count;

   

    //check if "MyView1" exists

    var hasView1 = false;

    for(var i=1; i <= savedviewscount;i++ ){

        var eachView =  state.SavedViews().Item(i);

        {

            if(eachView.Name == "MyView1")

            {

                hasView1 = true;

                break;

            }

        }

    }

   

    if(!hasView1)

    {

        //make a copy of the current view. It is the anonymous viewpoint.

        var currentView =

           state.CurrentView.Copy();

        //create a new object with the type:

        var oNewView =

           state.ObjectFacto
ry( state.GetEnum(
"eObjectType_nwOpView")) ;

        oNewView.Name = "MyView1";

       

        //attach the anonymous viewpoint to the new view.             

        oNewView.anonview = currentView;

        //add the new view to the saved viewpoints collection

        state.SavedViews().Add(oNewView);               

    }

}

 

function applyView1()

{

    //assume nwviewer is the object of ActiveX control.

    var state = nwviewer.state;

    var savedviewscount = state.SavedViews().count;

 

    //check if "MyView1" exists

    var hasView1 = false;

    for (var i = 1; i <= savedviewscount; i++) {

        var eachView = state.SavedViews().Item(i);

        {

            if (eachView.Name == "MyView1") {

                hasView1 = true;

                break;

            }

        }

    }

 

    if (hasView1) {

        //if "MyView1" exists, switch the view to "MyView1"

        state.ApplyView(eachView);

    }

}

<

p style=”line-height: normal;margin: 0cm 0cm 0pt” class=”MsoNormal” align=”left”> 


Comments

One response to “Create New Saved Viewpoint in Javascript”

  1. It seems like adding a viewpoint with the comapi seems to slow down the more viewpoints there are in the file system, this does not occur when adding using the net api. The slowdown seems to be very significant once you reach about 300 views. Perhaps the comapi is reindexing the file system on every add call and the net api defers this process. Considering the comapi is the only way to apply material and hide attributes, this bottleneck of performance is significant. Do you have any work arounds to convert a InwOpView to a Viewpoint without losing the applied attributes?

Leave a Reply to Mason T.Cancel reply

Discover more from Autodesk Developer Blog

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

Continue reading