#
# This example shows how to add an attribute and set its data.
#
from win32com.client import constants
xsi = Application
xsi.NewScene("", "false")
xsi.CreatePrim("Cone", "MeshSurface", "", "")
#Type = Vector3, context = One element per polygon.
attr = xsi.Selection(0).ActivePrimitive2.AddICEAttribute("MyVec3", constants.siICENodeDataVector3, constants.siICENodeStructureSingle, constants.siICENodeContextComponent2D );
myDataArray = [ XSIMath.CreateVector3( 0.0, 0.0, 0.0 ) ] * attr.ElementCount
myDataArray[0] = XSIMath.CreateVector3( 1.0, 2.0, 3.0 )
myDataArray[1] = XSIMath.CreateVector3( 4.0, 5.0, 6.0 )
attr.DataArray = myDataArray
#Type = String, context = One element per vertex or point.
attr = xsi.Selection(0).ActivePrimitive2.AddICEAttribute("MyString", constants.siICENodeDataString, constants.siICENodeStructureSingle, constants.siICENodeContextComponent0D );
myDataArray = [ "" ] * attr.ElementCount
myDataArray[0] = "text"
myDataArray[1] = "why"
myDataArray[2] = "How"
attr.DataArray = myDataArray
#Type = Quaternion, context = One element per geometry.
attr = xsi.Selection(0).ActivePrimitive2.Geometry.AddICEAttribute("MyQuat", constants.siICENodeDataQuaternion, constants.siICENodeStructureSingle, constants.siICENodeContextSingleton );
myDataArray = [ XSIMath.CreateQuaternion( 1.0, 2.0, 3.0, 4.0 ) ] * attr.ElementCount
myDataArray[0] = XSIMath.CreateQuaternion( 1.0, 2.0, 3.0, 4.0 )
attr.DataArray = myDataArray
#Type = Rotation, context = One element per edge.
attr = xsi.Selection(0).ActivePrimitive2.Geometry.AddICEAttribute("MyRot", constants.siICENodeDataRotation, constants.siICENodeStructureSingle, constants.siICENodeContextComponent1D );
myDataArray = [ XSIMath.CreateRotation( 0.0, 0.0, 0.0 ) ] * attr.ElementCount
myDataArray[0] = XSIMath.CreateRotation( XSIMath.DegreesToRadians( 70 ), XSIMath.DegreesToRadians( 40 ), XSIMath.DegreesToRadians( 45 ) )
myDataArray[1] = myDataArray[0]
myDataArray[2] = myDataArray[0]
attr.DataArray = myDataArray
# Display the first values of the newly added attributes
attrs = xsi.Selection(0).ActivePrimitive2.Geometry.ICEAttributes;
for attr in attrs:
if attr.Name.find("My") == -1 :
continue
xsi.LogMessage( "*******************************************************************" )
xsi.LogMessage( "Name: " + attr.Name )
xsi.LogMessage( "Element count: " + str(attr.ElementCount) )
if attr.IsDefined == 0 :
continue
dataType = attr.DataType;
data = attr.DataArray;
i = 0
for elem in data:
i += 1
if i > 4 :
continue
elif dataType == constants.siICENodeDataVector3:
xsi.LogMessage( "Vector3: (" + str(elem.X) + ", " + str(elem.Y) + ", " + str(elem.Z) + ")" )
elif dataType == constants.siICENodeDataQuaternion:
xsi.LogMessage( "Quaternion: (" + str(elem.W) + ", " + str(elem.X) + ", " + str(elem.Y) + ", " + str(elem.Z) + ")" )
elif dataType == constants.siICENodeDataRotation:
xsi.LogMessage( "Rotation: (" + str(round(elem.RotX)) + ", " + str(round(elem.RotY)) + ", " + str(round(elem.RotZ)) + ")" )
elif dataType == constants.siICENodeDataString:
xsi.LogMessage( "String: " + elem );
# Expected results:
# INFO : *******************************************************************
# INFO : Name: MyQuat
# INFO : Element count: 1
# INFO : Quaternion: (1.0, 2.0, 3.0, 4.0)
# INFO : *******************************************************************
# INFO : Name: MyRot
# INFO : Element count: 56
# INFO : Rotation: (70.0, 40.0, 45.0)
# INFO : Rotation: (70.0, 40.0, 45.0)
# INFO : Rotation: (70.0, 40.0, 45.0)
# INFO : Rotation: (0.0, 0.0, 0.0)
# INFO : *******************************************************************
# INFO : Name: MyString
# INFO : Element count: 26
# INFO : String: text
# INFO : String: why
# INFO : String: How
# INFO : String:
# INFO : *******************************************************************
# INFO : Name: MyVec3
# INFO : Element count: 32
# INFO : Vector3: (1.0, 2.0, 3.0)
# INFO : Vector3: (4.0, 5.0, 6.0)
# INFO : Vector3: (0.0, 0.0, 0.0)
# INFO : Vector3: (0.0, 0.0, 0.0)
|