Monday, April 30, 2012

Creating a Netview Tool

How do you create a custom tool having complex user interface?
Using a PPG Layout? very good. But, I like to create a tool using Netview.
This time, I will write how to creat a custom Netview tool.

1) The first step is creating a relational view.
    Open the relational view editor by choosing View > New Custom Relational View.

2) Input the name of your tool to the 'View Name' textbox.
    Choose an item from the Set View > Netview in the right-click menu.
   
3) Setting to be invisible the toolbar of the Netview.
   Choose an item from the Toolbar > None in the right-click menu.
  
 
4) The next step, Create the HTML file of your tool.
    The following is the source code template of the Netview tool.
    Please, modify this code and save.

<html>
<head>
<title>My Netview Tool</title>
<script language = "javascript">
//*** Basic information of this tool ***
//Please modify these parameters.

//The name of this tool. 
//You have to make it the same as the name of the relational view.
var gsThisToolName = "My Netview Tool";  
//The view's width
var gnViewWidth = 220;
//The view's Height
var gnViewHeight =160;
//Single view mode or not
var gbSingleMode = true;

//*** End basic information ***

var xsi; //The softimage application object 
initTool();

function initTool(){
 //Get the softimage application object
 var xsiApp = new ActiveXObject( "XSI.Application" ) ; 
 xsi = xsiApp.application;

 //If this tool is single view mode, only one view is opened.
 if(gbSingleMode){
  var oViewList = xsi.Desktop.ActiveLayout.views;
  var oViewListCount = oViewList.count;
  var f = false;
  for(var i = 0; i < oViewListCount; i++){
   var oView = oViewList(i);
   if(oView.type == gsThisToolName){
    if(!f){
     oView.state = 0;
     oView.Resize(gnViewWidth, gnViewHeight);
     f = true;
    }else{
     oView.state = 1;
    }
   }
  }
 }
}

//*** User functions ***
//Please modify as you like.
function myRBt_onClick(in_Val){
 xsi.SetViewCamera(in_Val, 1);
}

function myCheck01_onClick(in_Val){
 var oCamera = xsi.GetViewCamera(1);
 xsi.SetValue(oCamera + ".camvis.gridvis", in_Val, null);
 xsi.SetValue("Views.ViewB.*.camvis.gridvis", in_Val, null);
}

function myCheck02_onClick(in_Val){
 var oCamera = xsi.GetViewCamera(1);
 xsi.SetValue(oCamera + ".camvis.selectioninfo", in_Val, null);
 xsi.SetValue("Views.ViewB.*.camvis.selectioninfo", in_Val, null);
}
//*** End user functions ***

</script>
</head>
<body bgcolor="#aba8a6" topmargin="3" leftmargin="3" scroll="no">
<font size="2">
<!-- HTML body. Please modify as you like. -->
<b>Sample</b><br>
<!-- Radio buttons. -->
<input type="radio" name="myRButton" checked onClick="myRBt_onClick('user');">User
<input type="radio" name="myRButton" onClick="myRBt_onClick('top');">Top
<input type="radio" name="myRButton" onClick="myRBt_onClick('front');">Front
<input type="radio" name="myRButton" onClick="myRBt_onClick('right');">Right
<hr>
<!-- Checkbox -->
<input type="checkbox" name="myCheck01" checked onClick="myCheck01_onClick(this.checked);">Grid
<input type="checkbox" name="myCheck02" onClick="myCheck02_onClick(this.checked);">Selection Info
<hr>
<!-- Text Field -->
<input type="text" name="myText" size="24" value="Hello, world!" onChange="xsi.logmessage(this.value);"
 onKeypress="javascript: if(event.keyCode==13)this.blur();">
<hr>
<!-- Button -->
<input type="button" name="myButton01" value="Cube" onClick="xsi.CreatePrim('Cube', 'MeshSurface', null, null);">
<input type="button" name="myButton02" value="Sphere" onClick="xsi.CreatePrim('Sphere', 'MeshSurface', null, null);">
<br>

</font>
</body>
</html>

5) Open the View_Properties window by choosing Set View Properties in the
    right-click menu.  And enter the address or the file path of the HTML file.

   
6) Then, Save the relational view by choosing File > Save in the right-click menu.
    You can open your tool from the view menu. But, your tool menu is under 'Others'.

7) Open the xsivw file with a text editor.
   Enter the category name as you like in the category property.


   You can open your tool from the menu set by you.