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).

10 thoughts on “Scripting – Writing the DataArray of an ICE attribute

  1. You might want to take a look at your listing: The “&quot” as stand-in for each and every quotation mark doesn’t help its readability. 😉

  2. thanks, i needed this and was to lazy to figure out myself yet.
    I will do a attempt to get the jscript to work.

    Anyway for your python script, why does the myScalarArray show up so strange:

  3. I tried half a hour to get the jscript to work.
    I had problems with arrays before since jscript is a bit different from javascript.
    Anyway, do you think this is a bug in softimage?

  4. related to this topic
    i’m so interested in this.

    i never used python but i heard it’s great for reading csv files. Also i got sick of the small differences between jscript and javascript. Whenever you google it assumes jscript is javascript.
    I did some searches for creating a array in python but i can’t find anthing related to something that looks like:

    a.DataArray = [[ 122, 123, 124, 125]]

    why the [[ instead of a single [ ?

    And if somone could help me with creating the nodes or a ppg mentioned in the topic above then that would be really great.

      • there is DataArray and DataArray2D, in the example above you use DataArray instead of DataArray2D.
        But if you create a list of lists, isn’t that supposed to be a 2d array?

      • There is no reply button under:
        “DataArray2D would be for per-point attributes (or per-sample or per-polygon or …)”

        So this might end a bit to high.

        DataArray2D can also be per-object so i still don’t get it.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s