JScript Revisited

‘Things are only impossible till they’re not’ – Capt Picard…

An interesting exercise Walt. Looking forward to seeing your new scripts <!– s:) –><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!– s:) –>

Paul

I thought a good introduction to 3DC’s data structures would be to take a sample VBS script and transliterate it to JScript. That way I would have to make sure I really knew what was going on. Seeking what had gone before me, I did a forum search for ‘JScript,’ but didn’t find much — certainly not any success. I was concerned when I read of a user finding that, in JScript, the 3DC GetPosition method would not return the x,y,z position values.

I undertook my own probe by first getting camera position in VBS, just a half-dozen lines or so. Then I transliterated to JScript. Whoops! The values returned were ‘undefined’. Then I realized, of course, VBS has functions and subroutines; JScript has only functions. And, with JScript functions, numbers are always passed in by value. To get the coordinate values from GetPosition, I need something that communicates the values by reference, something that JScript doesn’t do.

In light of this, I think it’s incorrect to state that JScript can be used for scripting 3DC. Given the significant number of numerical parameters that are communicated by reference, JScript can’t in any useful way.

Am I right?

Incidentally, I did use an alternative (Popup) to get the equivalent of MsgBox. And I cobbled up a way of allowing JScript to communicate the VBS object Nothing.

Darned if I didn’t find a way to get JScript to work with 3DC. The key that kept me working was discovering that 3DC can be opened and controlled with an [b:3ks5ttnx]external[/b:3ks5ttnx] script. The progid to reference when creating a COM object is 3DC6.3DCScene. (There may be others that are useful.)

Recall from my previous post that there were two problems that JScript couldn’t handle: (1) It has no Nothing object, and (2) it can’t retrieve values passed by reference. I knew that Windows Script Files (.wsf) allow you to work both sides of the VBS/JScript fence, and this might enable me to try to get the two languages to interoperate to solve the problem. I tried (unsuccessfully) to get 3DC to work with WSF internally. But, now that the script could be external, I had a chance.

Getting the Nothing object from VBS was easy. I chose to call a VBS function that passes it back.

To get at a solution for the second problem, I called a VBS function designed to return position for a group. The arguments were the group object and the reference group object (where I used my Nothing). This VBS function calls the GetPosition method, retrieving the x,y,z position by reference. Further it stores the three values in a VBS array and returns it to JScript.

Here, I was disturbed to discover that arrays are implemented totally differently between VBS and JScript. Fortuitously, JScript has a function to convert arrays from VBS to JScript.

The attached WSF has the details for this simple test case. I’ll continue to explore the method. There will be some more VBS ‘cover’ functions to write, but they are pretty simple. The payoff will be that the arrays may be pretty convenient to work with.

I should add that the WSF approach enables implementing useful VBS utilities (e.g., InputBox) for JScript.

Finally, now that I’ve proved feasibility with an external script, it occurs to me that I might be able to do the same thing by packaging the VBS functionality in a COM control for use by an internal JScript.

Confirmed that the same approach works with JScript from inside 3DC. VBS helper functions are implemented in an ActiveX control.

You must be logged in to reply in this thread.

4 posts