Running Scripts in Netview

 
 
 

You can create Netview pages that not only set data in Softimage, but also get data from Softimage and display dynamic info. For example, you can write a suite of scripts for custom tools, and build the user interface with dynamic HTML, forms, and buttons in a Web page. There's no end to the possibilities, but this section should help you get started.

NoteTo run simple scripts from a Netview page as if they were running from the script editor, see Linking to Scripts.

Setting Security

Before you can run scripts from Netview, 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.

ImportantBe 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.

ImportantModifying the security setting for a domain affects all programs on your computer, not just Softimage.

To set Internet security levels 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_2013
  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.

Running Embedded Scripts Automatically

Scripts that are embedded in the body of an HTML page are parsed and run automatically when the page is loaded into Netview. Global code (that is, code that is not within any procedure) is executed, together with functions or subroutines that are called from the global code.

For example:

<body>
<!-- HTML elements go here -->
...
<script language="vbscript">
'Global code 
'This gets executed automatically
...
sub mySub()
'This procedure is executed only when it is called
...
end sub
</script>
<!-- More HTML elements go here -->
...
</body>

Running Embedded Script Code from Buttons and Hotspots

You can run script code when your users click a button or hotspot on the HTML page. To do this, write a procedure and then call the procedure from the onclick event of the button or hotspot.

For example, to create an HTML button that runs mySub using VBScript:

<script language="vbscript">
...

sub mySub()
'Code goes here
end sub
...

</script>
...

<input id=bClickMe
		type=button
		value="Click Me"
		name=button1
		language=vbscript
		onclick="mySub()">

Communicating with Softimage

Your Netview script must link to Softimage before it can get and set data. This is because a script in Netview is actually running inside Internet Explorer, and therefore needs to get a pointer to Softimage before it can communicate. To get the pointer, your script must instantiate the XSI.Application object.

For in example, in VBScript:

On Error Resume Next

Set myXSI = CreateObject("XSI.Application")
Set myApp = myXSI.Application

if err.number <> 0 then
	document.write "Open this page in Softimage's Netview."
end if

Once you have a pointer to XSI.Application, you can prepend it to the name of any object, method, or property in the Softimage object model. For example, to get the current selection in Softimage using VBScript:

Set mySel = myApp.Selection

Running Softimage Script Commands

Getting a pointer to the XSI.Application object, as described in the previous section Communicating with Softimage, allows you to use Softimage objects, methods, and properties in your Netview scripts. But what if you need to use a Softimage script command for which there is no equivalent in the object model? Luckily, there are a few ways to accomplish this.

NoteSome "commands", like LogMessage and Version, are actually methods of the Application object. You can run these methods without any workaround.

Running script commands via COM automation

Once you have a pointer to XSI.Application, you can use it to run any Softimage script command via COM automation. For example:

'Get a pointer to XSI.Application
Set myXSI = CreateObject("XSI.Application")
Set myApp = myXSI.Application
'Get the selection
Set mySel = myApp.Selection
'Run a command, e.g. InspectObj
myApp.InspectObj(mySel(0))

Running script commands with ExecuteScriptCommand

The ExecuteScriptCommand method of the XSIApplication object lets you run Softimage scripting commands, including custom commands. Although this method is primarily intended to run commands from COM C++, you can also use it in Netview. You must package the arguments in an array beforehand. For more information see ExecuteScriptCommand [SDK Guide].

Running script files with ExecuteScript

The ExecuteScript method of the XSIApplication object lets you run a script file rather than a single Softimage scripting command. You must package the arguments in an array beforehand. For more information see ExecuteScript [SDK Guide]

Displaying Data Dynamically

You can display information from Softimage dynamically in a Netview page.

  1. Create a <div> element in the body of the HTML to hold the data that you will write, and give it a unique ID. For example:

    <div id="myDiv"> </div>

    If desired, you can put default text or other HTML elements between the opening and closing div tags.

  2. Write a routine that builds a string of text in HTML format and assigns it to the innerHTML property of the <div>.

    For example in VBScript:

    Sub writeSel()
    
    Set mySel= myApp.Selection
    
    if mySel.Count <> 0 then
    	myStr = ""
    	for each thing in mySel
    		myStr = myStr & "<p>My name is <b>" & thing.Name & "</b>.</p>"
    	next
    else
    	myStr= "<p>Select an object first.</p>"
    end if
    
    myDiv.innerHTML= myStr
    End Sub
  3. Call the routine in some way. For example, to make a button that calls a VBScript subroutine:

    <input id=bWhoAmI
    		type=button
    		value="Who am I?"
    		name=button1
    		language=vbscript
    		onclick="writeSel()"
    		>

Sample Dynamic HTML Page

Look in the Netview Help page for a simple example of a page that gets a pointer to Softimage, runs a script from a button, and prints the name of the selected object dynamically.