简体   繁体   中英

Converting an Array of Objects to a COM Variant Array from JavaScript

I'm currently struggeling a little with a problem concerning an ActiveX-Interface and specifically a Variant-Array. I found some answers how to achieve the conversion but unfortunately nothing worked for me so far. Maybe you can help me. Here's my problem:

I have some Objects i retrieved via the ActiveXInterface. Now one ActiveX-Method requires to have two of these objects in an array.

In VB this is what you basically do

Dim aVar1(1)
Set aVar1(0) = oReferenceLine1
Set aVar1(1) = oReferenceLine2

After that you pass this array to a function like this

Set oNewJoint = oNewMechanism.AddJoint("CATKinCylindricalJoint",aVar1)

Work with everythin i retrieve via the interface works fine, but i am unable to create an array to pass that function. One approach I found to solve this issue was this

var vbArray = new ActiveXObject('Scripting.Dictionary');
$.each(JSArray, function(index){
    vbArray.add(index, JSArray[index]);
});

return vbArray.Items();

However if I do this. I just get back an undefined. vbArray gets created and I can access eg vbArray.Item(1) but vbArray.Items() just keeps returning undefined and calling the function

var joint = mechanism.ActiveXObject.AddJoint('CATKinCynlindricalJoint', vbArray);

just keeps returning a TypeConflict

It would be great if someone has an idea how I can put those two objects in an array and pass them as a variant array to my Application.

As often I was looking in the wrong direction for the error. Even though I couldn't (and still) can't read the contents of the vbArray it's not empty. After i corrected the typo in 'CATKinCynlindricalJoint'

I noticed that when I used the vbArray.Items() as an argument I got the error that the AddJoint-Method failed. If I just tried the Method with undefined I got a TypeConflict returned. So obviously vbArray.Items() was not really undefined.

After that i noticed that I was using a wrong argument to build my References and conversion to a vbArray did actually work. The error I made goes pretty much into detail with Catia, so I won't dive into it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM