Python Object Model Basics (XSISDK)
How to get up and running quickly with Python and XSI.....
Also see
| Table of contents |
[edit]
Example of Enumerating Properties in Python
#Example of Enumerating Properties in Python
oDefaultLight = Application.ActiveSceneRoot.Children( "light" )
for oProp in oDefaultLight.Properties:
Application.LogMessage( oProp.Name )
#Example output:
#INFO : Kinematics
#INFO : Display
#INFO : Visibility
[edit]
Example of Enumerating Edges
#Example of Enumerating Edges
oObj = Application.ActiveSceneRoot.AddGeometry("Cone","MeshSurface")
oEdges = oObj.ActivePrimitive.Geometry.Edges
for oEdge in oEdges:
index = oEdge.Index
Application.LogMessage( "Found edge %d" % index )
[edit]
Using the XSI Math Library from Python
#Using the XSI Math Library from Python v3 = XSIMath.CreateVector3() #Vector can be set via its properties v3.X = 10.0 #Or via this method v3.Set( 10.0, 20.0, 30.0) #Vector3 has many convenient methods v3.ScaleInPlace(2) #Read the vector values x=0 y=0 z=0 x, y, z = v3.Get(x,y,z) valstr = '%(x).2f %(y).2f %(z).2f' % vars() Application.LogMessage( valstr ) ; #Output: #INFO : 20.00 40.00 60.00
[edit]
Demonstration of how returned arrays are representing as Tuples in Python
#Demonstration of how returned arrays are representing as Tuples in Python oObject = Application.ActiveSceneRoot.AddGeometry( "Grid","MeshSurface","PolyMeshGetTest" ) Application.SetValue(str(oObject) + ".polymsh.geom.subdivu", 1, "") Application.SetValue(str(oObject) + ".polymsh.geom.subdivv", 1, "") oGeometry = oObject.ActivePrimitive.Geometry aReturnArray = oGeometry.Get2() ; Application.LogMessage( repr(aReturnArray) ) ; #Output: #INFO : (((-4.0, -4.0, 4.0, 4.0), (0.0, 0.0, 0.0, 0.0), (-4.0, 4.0, -4.0, 4.0)), (4, 0, 1, 3, 2)) aVertices = aReturnArray[0] # 2D array of x,y,z aPolydata = aReturnArray[1] Application.LogMessage( repr(aVertices) ) ; #Output: #INFO : ((-4.0, -4.0, 4.0, 4.0), (0.0, 0.0, 0.0, 0.0), (-4.0, 4.0, -4.0, 4.0)) Application.LogMessage( repr(aPolydata) ) ; #INFO : (4, 0, 1, 3, 2)
[edit]
Demonstration of how XSI arrays are representing as Tuples in Python
#Demonstration of how XSI arrays are representing as Tuples in Python oObject = Application.ActiveSceneRoot.AddGeometry( "Grid","MeshSurface","PolyMeshGetTest" ) Application.SetValue(str(oObject) + ".polymsh.geom.subdivu", 1, "") Application.SetValue(str(oObject) + ".polymsh.geom.subdivv", 1, "") oGeometry = oObject.ActivePrimitive.Geometry #Call PolygonMesh.Get which uses Output Arguments aVertices = []; aPolydata = []; aVertices,aPolydata = oGeometry.Get(aVertices,aPolydata) ; #According to the docs the vertices are represented as: #"Array representing the polygon vertices. The array is a 2D array (Nx3) of x,y,z values." #In python the 2D array is flattened into a tuple of tuples. #First element is all the x values for the 4 vertices, #second element is all the y values and #third element is all the z values. Application.LogMessage( repr(aVertices) ) ; #Output: #INFO : ((-4.0, -4.0, 4.0, 4.0), (0.0, 0.0, 0.0, 0.0), (-4.0, 4.0, -4.0, 4.0)) Application.LogMessage( "Vertex 0 is at (%d,%d,%d)" % \ (aVertices[0][0], aVertices[1][0] ,aVertices[2][0])) #Output: #INFO : Vertex 0 is at (-4,0,-4) Application.LogMessage( repr(aPolydata) ) ; #Output: #INFO : (4, 0, 1, 3, 2)
This page was last modified 08:01, 31 Aug 2007.
This page has been accessed 3381 times.

