Passing a safe array into a method from JScript


In the XSI SDK, when a method or command returns an array, it returns a safe array.
So, in JScript, you have to use VBArray.toArray() to convert the safe array to a JScript array.

When you go in the other direction, and pass in an array, the XSI SDK automatically converts the JScript array to a safe array. That’s good, because you can’t build safe arrays in JScript, or convert JScript arrays to safe arrays.

Unfortunately for me, a customer came across a case where PPGItem.SetAttribute wouldn’t work with a JScript. Sure, it was with an undocumented attribute, but still…

I knew the JScript attribute was the problem because I could set the attribute in VBScript, but not JScript.

So I came up with a hack to get a safe array in JScript. I used ExecuteScriptCode to call a VBScript function that returned a safe array, which I could then pass to SetAttribute.

var s = "function a( val )\n" + 
	"a = Array( val )\n" +
	"end function";

var sa = Application.ExecuteScriptCode( 
			s, "VBScript", "a", val );

Another way to get a safe array in JScript is to use the Scripting.Dictionary. The Items method returns a safe array:

d = new ActiveXObject("Scripting.Dictionary"); 
d.Add( 0, val )
var sa = d.Items();

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s