Scripting – Writing the DataArray of an ICE attribute


Here’s a little Python snippet that shows how to write to the DataArray of an ICE attribute.

from siutils import si
si = si()					# win32com.client.Dispatch('XSI.Application')
from siutils import log		# LogMessage
from siutils import disp	# win32com.client.Dispatch
from siutils import C		# win32com.client.constants

pc = si.GetPrim("PointCloud", "", "", "")
a = pc.ActivePrimitive.AddICEAttribute("MyScalarArray", C.siICENodeDataFloat, C.siICENodeStructureArray, C.siICENodeContextSingleton  )
a.DataArray = [[ 0.03, 3.33, 2.22, 3.333 ]]

a = pc.ActivePrimitive.AddICEAttribute("MyLong", C.siICENodeDataLong, C.siICENodeStructureSingle, C.siICENodeContextSingleton  )
a.DataArray = [3.1416*1000]

a = pc.ActivePrimitive.AddICEAttribute("MyScalar", C.siICENodeDataFloat, C.siICENodeStructureSingle, C.siICENodeContextSingleton  )
a.DataArray = [3.1416]

#
# Add some Attribute Display properties
# to show the attribute values
#

p = pc.AddProperty( "AttributeDisplay", False, "" )
p.Parameters( "attrname" ).Value = "MyScalar"

p = pc.AddProperty( "AttributeDisplay", False, "" )
p.Parameters( "attrname" ).Value = "MyLong"
p.Parameters( "offsety" ).Value = 16

p = pc.AddProperty( "AttributeDisplay", False, "" )
p.Parameters( "attrname" ).Value = "MyScalarArray"
p.Parameters( "offsety" ).Value = 32

I tried to do the same thing in JScript, but I couldn’t get it to work for arrays. Very frustrating.

pc = GetPrim("PointCloud", "", "", "");

a = pc.ActivePrimitive.AddICEAttribute("MyScalarArray", siICENodeDataFloat, siICENodeStructureArray, siICENodeContextSingleton  )

a.DataArray = [[ 0.03, 3.33, 2.22, 3.333 ]]
// WARNING : 3390 - This ICEAttribute doesn't refer to a 2D array: <Attribute: MyScalarArray>
//

a.DataArray = [ 0.03, 3.33, 2.22, 3.333 ]
// WARNING : 3392 - Invalid offset specified while extracting data from this attribute: <Attribute: MyScalarArray>
// <Offset: 108384008>
// 


// But this does works
a = pc.ActivePrimitive.AddICEAttribute("MyLong", siICENodeDataLong, siICENodeStructureSingle, siICENodeContextSingleton  )
a.DataArray = [3000]

PS You can find some usage of DataArray in the CrowdFX plugin (in the Softimage install dir).