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.ObjectFactory( 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);
}
}