- In Jscript, the array needs to be converted to safearray before you can set 
it on ICE attribute data. Check out the code below for the conversion.
- As a workaround for setting MaterialID, you can store the data in a custom 
attribute, then use ICE to read from it and set MaterialID

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();
}

//to a safe array
var safearr = getSafeArray([1,2,1,2,1,2]);

//back to a js array
//var jsArr = new VBArray(safearr).toArray();

cube = Dictionary.GetObject("cube")

attr = cube.ActivePrimitive.Geometry.AddICEAttribute("CustomMaterialID", 
siICENodeDataType.siICENodeDataLong, 
siICENodeStructureType.siICENodeStructureSingle, 
siICENodeContextType.siICENodeContextComponent2D)
attr.DataArray = safearr

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Stephen Blair
Sent: Tuesday, March 12, 2013 7:29 PM
To: [email protected]
Subject: Re: setting ICEAttribute.DataArray in JScript

Last time I tried, I gave up on JScript (it seemed impossible) and got 
something to work in Python.

si = Application
from win32com.client import constants as C            # 
win32com.client.constants

oObj = si.Selection(0)
oICEAttrMats = oObj.ActivePrimitive.AddICEAttribute("MyString",
C.siICENodeDataString, C.siICENodeStructureArray,
C.siICENodeContextSingleton)
oICEAttrMats.DataArray2D = ["a", "b", "c", "d"]

x = oICEAttrMats.DataArray2D
print x
print len(x)
print len(x[0])
print len(x[0][0])

for d in x[0][0]:
     print d


# (((u'a', u'b', u'c', u'd'),),)
# 1
# 1
# 4
# a
# b
# c
# d





On 12/03/2013 5:18 AM, Eugen Sares wrote:
> Ok... I'm trying this workaround:
> - Create custom ICEAttributes instead of the factory ones via 
> scripting, with exactly the same type.
> - Create a simple ICE graph that reads from the custom attributes and 
> writes to the factory attr via scripting.
>
> I've managed to write the "MaterialID" this way, but with "Materials" 
> I have the problem that I cannot create an equal string array custom
> attribute:
>
> <JScript>
> var oObj = CreatePrim("grid", "MeshSurface", "", ""); oICEAttrMats = 
> oObj.ActivePrimitive.AddICEAttribute("MyString",
> siICENodeDataString, siICENodeStructureArray, 
> siICENodeContextSingleton); oICEAttrMats.DataArray = ["a", "b", "c", 
> "d"]; </JScript> // WARNING : 3392 - Invalid offset specified while 
> extracting data from this attribute: <Attribute: MyString>
>
> The DataType, StructType and ContextType of that string array 
> attribute is exactly the same as the factory "Materials" attribute.
> (I checked in XSI_SAMPLES\ICE\Modelling_Materials.scn)
>
> What's wrong now?
> Thanks,
> Eugen
>
>
>
> Am 11.03.2013 18:46, schrieb Stephen Blair:
>> I don't think it is possible.
>>
>> MaterialID becomes undefined/uninitialized pretty quick...
>> http://screencast.com/t/HeNPz4qgwlh
>>
>> On 11/03/2013 12:25 PM, Eugen Sares wrote:
>>> Thanks, Steven!
>>> IsDefined is read-only, by the looks.
>>> So how do I write to it to define it (outside of ICE), when it 
>>> cannot be written until it's defined??
>>>
>>>
>>> Am 11.03.2013 17:15, schrieb Stephen Blair:
>>>> MaterialID isn't defined. Seems that you cannot set 
>>>> MaterialID.DataArray unless IsDefined is True
>>>>
>>>> On 11/03/2013 11:44 AM, Eugen Sares wrote:
>>>>> Whereas this throws a warning:
>>>>> <JScript>
>>>>> NewScene("", "false");
>>>>> var oObj = CreatePrim("grid", "MeshSurface", "", ""); 
>>>>> SetValue("grid.polymsh.geom.subdivu", 2, null); 
>>>>> SetValue("grid.polymsh.geom.subdivv", 2, null); var oICEAttr = 
>>>>> oObj.ActivePrimitive.GetICEAttributeFromName("MaterialID");
>>>>> oICEAttr.DataArray = [0,1,2,3]; // WARNING : 3403 - The data is 
>>>>> not set on this ICEAttribute: MaterialID
>>>>>
>>>>> var oProp = oObj.AddProperty("AttributeDisplay");
>>>>> SetValue(oObj.Name + ".AttributeDisplay.attrname", "MyLong", 
>>>>> null); </JScript>
>>>
>

<<attachment: winmail.dat>>

Reply via email to