Before you can run scripts from Net View, you must set the appropriate security level to Low for the domains on which the scripts reside. Low security allows all scripts and ActiveX content to run; to interact with Softimage, scripts must instantiate the XSI.Application ActiveX object.
![]()
|
Be very careful about which domains you set to low security. Malicious ActiveX content can damage your systems and data. It is strongly recommended that you use this setting for specific addresses on your private intranet only. |
To set Internet security levels on Windows
On Windows, you can set the security level for a specific domain in either of two ways:
• From within Internet Explorer.
or
• From the Windows Control Panel.
The exact procedure depends on the versions of Windows and Internet Explorer that you are using, so consult Internet Explorer’s online Help for details.
![]()
|
Modifying the security setting for a domain affects all programs on your computer, not just Softimage. |
To set Internet security levels for Softimage on Linux
On Linux, you can set the security level for a specific domain using the Mainwin Control Panel:
1. Open a terminal or shell window.
2. Source the Softimage environment script by typing:
source ~/.xsi_7.5
3. Launch the MainWin Control Panel by typing:
mwcontrol
4. Double-click on the Internet Options icon. The Internet Properties dialog box opens.
5. On the Security tab, select Trusted sites and then click the Sites button. The Trusted sites dialog box opens.
6. Type a domain address and click Add.
First we start with a really quick introduction to using HTML and DHTML to add scripts to your page. We don't touch Softimage yet, so these examples will also work in Internet Explorer (v4 and later).
It is possible to refer to an external script file, but this Primer only covers the more common case of embedding script code directly in the html. This is done with the HTML <SCRIPT> tag, which specifies the script language, for example:
<html> <head> <SCRIPT language="text/vbscript"> 'This is called when ever the page loads MsgBox "Script in head was called" </SCRIPT> </head> <body> <h1>Net View Scripting Primer - Example 1</h1> </body> </html>
Dynamically Changing the Content of Web Pages
Popping up message boxes gets irritating fast, what you often want to do is actually generate content for your page. For example you might want to scan a directory and list all the image files that you find there. Or even connect to a database and show the results of a query.
A convenient way to change the content of the web page dynamically is through an API called DHTML. This is an Object Model much like Softimage's object model, and it exposes the contents of the page as objects which you can change. There are a lot of details to it, which can be found easily on the internet, but you will be able to do a lot if you understand the use of the innerHTML property.
In the body of your HTML you can tag an element with a unique string, using the id attribute. For example:
<p id=MyTagName></p>
Next you can insert new html content inside this paragraph by adding a line like this inside your SCRIPT section:
document.all.MyTagName.innerHTML = "A String that can contain <b>html</b>" ;
In other words, at the time of display the page ends up with this content:
<p id=MyTagName>A String that can contain <b>html</b></p>
In the examples above document is a global variable (also called an Instrinsic object) that is available for access anywhere in your script. Here is an example showing this principal in action:
<html>
<body>
<h1>Net View Scripting Primer - Example 2</h1>
<H2 id=MyHeader2>Empty Header</h2>
<p id=MyParagraph></p>
<div id=MyDiv></div>
<SCRIPT language="text/jscript">
//It is important that this SCRIPT section
//appears after we declare our IDs
// Change the content using DHTML
document.all.MyHeader2.innerHTML = "Header Filled in By Scripting" ;
document.all.MyParagraph.innerHTML = "Paragraph filled <b>by scripting</b>";
document.all.MyDiv.innerHTML = "Using a div tag is convenient because " +
"you can nest any sort of other HTML content inside, for example" +
"<table border=1><tr><td>Generated Table</td></tr></table>";
</SCRIPT>
</body>
</html>
![]()
|
In this case you need to place your SCRIPT at the end of the body, after all the tags that you reference because the script needs to identify where to write HTML before trying to write it. |
You could also completely generate the whole content of the web page from your script. For example:
document.write "<H1>A header</H1><p>The content</p>"
However it is usually best to try to keep as much of the web formatting done with normal HTML in the body section, and then have your script fill in strategic parts of the page.
So far we have shown how to add dynamic content to an HTML page. However, often you want to react to some input from the user. For example your Net View page may show some information about objects in the scene and you want a Refresh button. Or you may want an edit box so that users can type in a file name or a number.
HTML supports some basic controls and the ability to execute event-based Script code. This is script code that doesn't execute when the page loads, but only executes when the user performs some action--for example clicking on a button. Here is a simple example:
<html>
<body>
<h1>Net View Scripting Primer - Example 3</h1>
<p>My favourite number:<b id="Fav">0</b></p>
<form id="myform">
<INPUT TYPE="edit" NAME="NewNumber" VALUE="1">
<INPUT TYPE="button" NAME="DoIt" VALUE="Change Number">
</form>
<SCRIPT language="text/vbscript">
sub DoIt_OnClick
document.all.fav.innerHTML = document.all.NewNumber.Value
end sub
</SCRIPT>
</body>
</html>
Because of its name, the subroutine DoIt_OnClick is recognized as the event handler to call whenever the button named DoIt is called.
This overview has only scratched the surface of what is possible with HTML and DHTML. Fortunately it is a very popular technology and is widely documented on the internet. Here are some links to get you started:
• DevGuru features a number of useful reference guides for HTML, DHTML, CSS2, and several scripting languages as well.
• MSDN offers an Introduction to Dynamic HTML.
• Webmonkey is an online resource providing tutorials and reference material on all topics related to web development.
• The W3C, or Worldwide Web Consortium, publishes technical specifications on web technologies and is the ultimate resource (although somewhat difficult to navigate for beginners).
• W3Schools offers tutorials on DHTML, as well as reference material on the HTML DOM (Document Object Model).
Now that we've seen an overview of how you can integrate scripts into a HTML page, we are ready to create pages that communicate with Softimage.
The most basic integration actually doesn't require the use of scripting at all. You can create web pages that link to image files, xsiaddons, scene files, script files and other files that Softimage will recognize. This can be a useful way to present content--for example when building a library of models.
For more sophisticated integration, such as writing custom tools, you can access the Softimage object model and Softimage commands inside your webpage. Such a page will only work when running inside Net View, it will not work when loaded in an external browser.
There are a few restrictions for scripts in Net View that are important to understand. Fortunately any changes you make will not break the script's ability to run as a normal script.
![]()
|
If you have an existing script that works in Softimage you may need to do some simple modifications before it will work as part of a Net View page. |
The specific differences are described in the next few sections:
• Accessing Application and other Global objects
• Calling a command from Net View
Accessing Application and other Global objects
When we are running a script from the Script Editor we have access to various global objects, including Application, XSIMath and XSIUtils. For example, an Softimage script might contain lines like this:
' Access global XSIMath object set oVec = XSIMath.CreateVector3 ' Access global Application Application.Logmessage "Hello world" 'In fact "Application." is optional LogMessage "logmessage shortcut"
In Net View none of these statements will work directly without a few minor modifications. This is because the global variables are not available. Fortunately it is easy to get access to these objects using CreateObject in VBScript or new ActiveXObject in JScript. For example:
set oXSIMath = CreateObject( "XSI.Math") ' Get access to the Application object set oXSIApplication = CreateObject( "XSI.Application") ' What we really want is the XSIApplication object set oXSIApplication = oXSIApplication.Application set oVec = oXSIMath.CreateVector3 oXSIApplication.LogMessage "Hello world" ' The shortcut is no longer available oXSIApplication.LogMessage "No logmessage shortcut"
Calling a command from Net View
Softimage commands are also not directly available from Net View. For example this script would not work:
' Call a Command SelectObj "MyCube"
Fortunately you can call any command by pretending it is a method of the Application object.
' vbscript set oXSIApplication = CreateObject( "XSI.Application") set oXSIApplication = oXSIApplication.Application oXSIApplication.SelectObj "MyCube"
Because you can reuse the oXSIApplication variable over and over again in your script you don't really need three lines of code for every call to a command:
' vbscript set oXSIApplication = CreateObject( "XSI.Application") set oXSIApplication = oXSIApplication.Application oXSIApplication.CreatePrim "MyCube" oXSIApplication.SelectObj "MyCube" oXSIApplication.InspectObj "MyCube" ' ... etc.
In Net View Softimage constants are not available. So rather than using a symbol name like siString, siXYZ or siEdgeCluster it is necessary to use the actual value of these constants, for example 8, 7 and "edge".
When converting an existing script this can lead to unexpected behavior that can be challenging to track down. The main problem is that scripting languages like VBScript and JScript allow variables to be defined on the fly so they will often treat these unrecognized variables as empty strings or the value zero.
For example, the statement Application.InstallationPath(siFactoryPath); is interpreted as Application.InstallationPath(0); on Net View, which returns the project path (siProjectPath)!
To avoid painful debugging of random and unexpected problems it is best to search for all the constants in a script--for example, by searching for the lowercase characters si. Replace each with its value. If you aren't sure what the value of a constant is you can look it up in the C# and Scripting Reference or just run a logmessage statement in Softimage; for example, LogMessage siXYZ prints 7.
Alternatively, because the constants are easier to read than the raw values, you can define values for all the constants at the top of your script. For example:
// jscript var siFactoryPath = 3; var oXSIApplication = new ActiveXObject( "XSI.Application" ); oXSIApplication = oXSIApplication.Application; logmessage( oXSIApplication.InstallationPath( siFactoryPath ) ) ;
The following example web pages are a VBScript Net View template and a JScript Net View template that you can use when building your own first Net View page.
<!--- Template for a Net View page that uses Scripting to communicate with Softimage.
To use this template refer to the sections flagged with "TODO"
--->
<html>
<head>
</head>
<body>
<h1>Net View VBScript Template</h1>
<p>....TODO: Put your HTML Content here, including text, tagged items, buttons
and other controls..</p>
<SCRIPT language="text/vbscript">
dim g_oXSIApp, g_oXSIMath, g_oXSIUtils, g_oXSIUIToolkit
if ( InitGlobals ) then
InitContent
end if
function InitGlobals()
//When creating the XSI.Application object we test
//to make sure we are really running in Net View.
//This allows us to give clear warning text rather than
//showing script errors or incomplete content
On Error Resume Next
set g_oXSIApp = CreateObject( "XSI.Application" )
if err.number <> 0 then
document.body.innerhtml = _
"<H1>This page needs to run inside Softimage Net View</H1>"
InitGlobals = false
exit function
end if
on error goto 0
set g_oXSIApp = g_oXSIApp.application
'TODO: Just uncomment any of these lines if you want
'to use one of these objects
'set g_oXSIMath = CreateObject( "XSI.Math" )
'set g_oXSIUtils = CreateObject( "XSI.Utils" )
'set g_oXSIUIToolkit = CreateObject( "XSI.UIToolkit" )
InitGlobals = true
end function
Sub InitContent
'TODO: Write code here to produce initial html content
'or do other actions when
'the page first loads
g_oXSIApp.LogMessage "InitContent called"
end sub
'TODO: Put any event handling scripts here, e.g.
'sub DoIt_OnClick
'Do something
'end sub
</SCRIPT>
</body>
</html>
<!--- Template for a Net View page that uses Scripting to communicate with Softimage.
To use this template refer to the sections flagged with "TODO"
--->
<html>
<head>
</head>
<body>
<h1>Net View JScript Template</h1>
<p>....TODO: Put your HTML Content here, including text, tagged items, buttons
and other controls....</p>
<SCRIPT language="text/jscript">
var g_oXSIApp, g_oXSIMath, g_oXSIUtils, g_oXSIUIToolkit ;
if ( InitGlobals() ) {
InitContent() ;
}
function InitGlobals() {
//When creating the XSI.Application object we test
//to make sure we are really running in Net View.
//This allows us to give clear warning text rather than
//showing script errors or incomplete content
try {
g_oXSIApp = new ActiveXObject( "XSI.Application" ) ;
}
catch(e) {
document.body.innerHTML =
"<H1>This page needs to run inside Softimage Net View</H1>" ;
return 0 ;
}
g_oXSIApp = g_oXSIApp.application
//TODO: Just uncomment any of these lines if you want
//to use one of these objects
//g_oXSIMath = new ActiveXObject( "XSI.Math" );
//g_oXSIUtils = new ActiveXObject( "XSI.Utils" );
//g_oXSIUIToolkit = new ActiveXObject( "XSI.UIToolkit" );
return 1 ;
}
function InitContent() {
//TODO: Write code here to produce initial html content
//or do other actions when
//the page first loads
g_oXSIApp.LogMessage( "InitContent called" ) ;
}
//TODO: Put any event handling scripts here, e.g.
//function DoIt_OnClick() {
//Do something
//}
</SCRIPT>
</body>
</html>
To demonstrate some of these concepts further, lets consider a simple script for printing out information about custom commands installed in Softimage. We start by prototyping the tool in the script editor:
logmessage "Installed Custom Commands"
for each oCommand in Application.Commands
if (NOT oCommand.builtin ) then
logmessage oCommand.name & ":" _
& oCommand.scriptingname
end if
next
After trying out we quickly realise that Net View would be an ideal tool because we could format the data into a table that would be a lot easier to read than looking in the script history.
We need to consider what changes will happen to the script to make it work in Net View. We scan for constants and realise that none are being used. However Application.LogMessage and Application.Commands won't work directly. We can stop using LogMessage entirely because we want to generate html content instead; and we can use the g_oXSIApp variable instead of Application to access the XSIApplication object.
Not only can we provide nicer presentation of static information in Net View, we can turn this example into a simple interactive tool but also allowing users to directly uninstall custom commands. This is done by adding a button to each row in the table and a few lines of script code. The result is shown below:
<html>
<head>
</head>
<body>
<h1>Net View Primer - Example 4</h1>
<h2>Installed Custom Commands</h2>
<!--- The generated table will be inserted inside the following div tags --->
<div id="CustomCommandTable"></div>
<SCRIPT language="text/vbscript">
<!-- based on the template -->
dim g_oXSIApp, g_oXSIMath, g_oXSIUtils, g_oXSIUIToolkit
if ( InitGlobals ) then
InitContent
end if
function InitGlobals()
On Error Resume Next
set g_oXSIApp = CreateObject( "XSI.Application" )
if err.number <> 0 then
document.body.innerhtml = _
"<H1>This page needs to run inside Softimage Net View</H1>"
InitGlobals = false
exit function
end if
on error goto 0
set g_oXSIApp = g_oXSIApp.application
InitGlobals = true
end function
Sub InitContent
'We will create html for the table as a string in memory
dim strTable
'Create the beginning of the table
strTable = "<TABLE><TBODY><TR>" &_
"<TH>Command</TH>" &_
"<TH>Script Name</TH>" &_
"</TR>"
'Notice how we use the g_oXSIApp to access Softimage
for each oCommand in g_oXSIApp.Commands
if (NOT oCommand.builtin ) then
'Add a row to the table
strTable = strTable & "<TR>"
strTable = strTable & "<TD>" & oCommand.Name & "</TD>"
strTable = strTable & "<TD>" & oCommand.ScriptingName & "</TD>"
'Create a button in the table that will specifically uninstall
'this command
strTable = strTable & "<TD><BUTTON OnClick=""OnRemoveScript '" & _
oCommand.Name & "'"">Uninstall</BUTTON></TD>"
strTable = strTable & "</TR>"
end if
next
'Finish the table
strTable = strTable & "</TBODY></TABLE>"
'Put the table into the document
document.all.CustomCommandTable.innerHTML = strTable
'Tip: to debug your generated html replace innerHTML with innerText as in:
'document.all.CustomCommandTable.innerText = strTable
end sub
sub OnRemoveScript( in_CommandName )
'Call the custom command
g_oXSIApp.RemoveCommand in_CommandName
'Regenerate the table
InitContent
end sub
</SCRIPT>
</body>
</html>
Turning Off Command Logging and Auto-inspection
Normally, scripts run from Net View log every command line to the command history. In addition, property editors open automatically when elements are created. However, you can turn off these behaviors temporarily in your script to speed up the performance of Net View scripts.
Using JScript in Net View Pages
When using JScript in Net View pages, you may find that it does not release objects after it has finished with them. This happens because JScript’s garbage collection is not predictable. However, you can force it to release objects by refreshing the Net View page.
Autodesk Softimage v7.5