First, let’s use Python to set up two ICE attributes with DataArray2D.
si = Application from win32com.client import constants as C # win32com.client.constants oObj = si.Selection(0) a = oObj.ActivePrimitive.AddICEAttribute("MyString", C.siICENodeDataString, C.siICENodeStructureArray, C.siICENodeContextSingleton) a.DataArray2D = [["a", "b", "c", "d", "e"]] a1 = oObj.ActivePrimitive.AddICEAttribute("MyString2", C.siICENodeDataString, C.siICENodeStructureArray, C.siICENodeContextSingleton) a1.DataArray2D = [["u", "v", "w" ]]
Now, let’s try to set DataArray2D with JScript. As a reminder, here’s how you access the DataArray2D in JScript:
o = Selection(0); a = o.ActivePrimitive.ICEAttributes("MyString"); x = VBArray( a.DataArray2D ).toArray(); LogMessage( VBArray( x[0] ).toArray() ); // INFO : a,b,c,d,e
Seeing that, you would think that you could set DataArray2D using an array of arrays or maybe an array, but no:
a.DataArray2D = [[ "a", "b", "c" ]]; // WARNING : 3390 - This ICEAttribute doesn't refer to a 2D array: <Attribute: MyString2> // a.DataArray2D = [ "a", "b", "c" ]; // WARNING : 3392 - Invalid offset specified while extracting data from this attribute: <Attribute: MyString2> // <Offset: 110348408> //
At this point, I started wondering if there was anyway at all to do it, so I tried to put back the same value:
a.DataArray2D = a.DataArray2D; // WARNING : 3393 - The input array doesn't match this attribute's data type or structure type: <Attribute: MyString2> //
Ack. Maybe if I converted it to a JScript array…well, at least something finally worked:
a.DataArray2D = VBArray( a.DataArray2D ).toArray();
Copying the DataArray2D from another attribute works too:
a = o.ActivePrimitive.ICEAttributes("MyString"); a1 = o.ActivePrimitive.ICEAttributes("MyString2"); a.DataArray2D = VBArray( a1.DataArray2D ).toArray();
So, based on that, I thought maybe I needed a safearray and things started getting a little hacky:
sa = getSafeArray( [ "a", "b", "c" ] ); jsa = new VBArray( sa ).toArray(); a.DataArray2D = sa; // WARNING : 3392 - Invalid offset specified while extracting data from this attribute: <Attribute: MyString2> // <Offset: 110348408> a.DataArray2D = jsa; // WARNING : 3392 - Invalid offset specified while extracting data from this attribute: <Attribute: MyString2> // <Offset: 110348408> // // Get a safearray from a JScript array // function getSafeArray(jsArr) { var dict = new ActiveXObject("Scripting.Dictionary"); for (var i = 0; i < jsArr.length; i++) dict.add(i, jsArr[i]); return dict.Items(); }
In summary, it doesn’t seem possible to set DataArray2D from JScript.