Scripting: Getting the StrandPosition arrays

StrandPosition is an array of arrays: one array of positions for each strand.

Here’s a Python snippet:

from win32com.client import constants
xsi = Application

def dispFix( badDispatch ):
    import win32com.client.dynamic
    # Re-Wraps a bad dispatch into a working one:
    return win32com.client.dynamic.Dispatch(badDispatch)

attr = xsi.Selection(0).ActivePrimitive.Geometry.ICEAttributes( "StrandPosition" )
dataType = attr.DataType
data2D = attr.DataArray2D
for data in data2D:
   for elem in data:
      elem = dispFix(elem)
      xsi.LogMessage( "Vector3: " + str(elem.X) + ":" + str(elem.Y) + ":" + str(elem.Z) )

And here’s a JScript snippet:

a = Selection(0).ActivePrimitive.Geometry.ICEAttributes( "StrandPosition" );
LogMessage( ClassName(a) );

x = a.DataArray2D.toArray();
LogMessage( x.length );
for ( var i = 0; i < x.length; i++ )
   y = x[i].toArray();
   LogMessage( "=======================" );
   for ( var j = 0; j < y.length; j++ )
      LogMessage( y[j].X + ", " + y[j].Y + ", " + y[j].Z );

More fun with arrays

Here’s a recent array question from the mailing list: How do you build an array that looks like this?

[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, ...] ?

I didn’t check the other answers yet, because that would be cheating 😉

When I look at that array, I see a repeating sequence of four integers, so that naturally suggests doing something with the Modulo node.


Using the If node is nice for clarity, but I could simply take the Boolean output of the comparison node.

ICE: Building an array from an fcurve

Suppose you have an animated scalar value, and you want to store its values as you play through a simulation. And suppose you also want to keep a running total of all the values up to the current frame.

My first try used two arrays: one to store the values at each step through the simulation, and one to hold the running total.

Calculating the array sum at every step seems wasteful. So, here’s my second try at keeping a running total of the values from the fcurve. I use just one attribute and one array. The attribute was necessary because if I plugged Pop from Array directly into Add, I got nothing.