Python Command Examples (XSISDK)

Python Example: Looping through a returned array

Application.GetPrim( "Null" )
Application.SetMarking( "kine.local.pos,kine.global.pos" )
Application.AddToMarking( "kine.local.ori" )
markings = Application.GetMarking()
for i in markings
   Application.LogMessage( "Value of item at index " + i + " = " + markings[i] )

# Expected result:
#INFO : Value of item at index 0 = kine.local.pos
#INFO : Value of item at index 1 = kine.global.pos
#INFO : Value of item at index 2 = kine.local.ori

Python Example: Getting the output arguments from commands

This example uses the GetKeyInfo command to demonstrate how to use the ISIVTCollection with Python. The GetKeyInfo command has no return value but uses nine output arguments, in this order: Parameter, LeftValue, RightValue, LeftTanParam, LeftTanValue, RightTanParam, RightTanValue, RightSegKind, and Constraints. For Python, these arguments are returned as an ISIVTCollection object.


from win32com.client import constants as c
Application.NewScene( Application.ActiveProject, 0 )
root = Application.ActiveSceneRoot

# Set up an fcurve on a null
oObj = root.AddNull()
aKeys = ( 1, -5.0, 25, 7.0, 50, 2.0 )
oFCurve = oObj.posx.AddFCurve2( aKeys, c.siDefaultFCurve )

# The GetKeyInfo command uses these output parameters (in order):
# Parameter LeftValue RightValue LeftTanParam LeftTanValue RightTanParam 
# RightTanValue RightSegKind Constraints 
ivtInfo = Application.GetKeyInfo( oFCurve, 1 )
Application.LogMessage( "# of items: " + str(ivtInfo.Count) )

# You can loop through the info
for entry in ivtInfo :
   Application.LogMessage( str(entry) )

# You can get the info by index:
i = ivtInfo.Count-1
while i >= 0 :
   Application.LogMessage( "Item" + str(i+1) + " = " + str(ivtInfo(i)) )
   i = i - 1

# You can get the info by name:
Application.LogMessage( "Parameter: " + str(ivtInfo.Value("Parameter")) )
Application.LogMessage( "LeftValue: " + str(ivtInfo.Value("LeftValue")) )
Application.LogMessage( "RightValue: " + str(ivtInfo.Value("RightValue")) )
Application.LogMessage( "LeftTanParam: " + str(ivtInfo.Value("LeftTanParam")) )
Application.LogMessage( "LeftTanValue: " + str(ivtInfo.Value("LeftTanValue")) )
Application.LogMessage( "RightTanParam: " + str(ivtInfo.Value("RightTanParam")) )
Application.LogMessage( "RightTanValue: " + str(ivtInfo.Value("RightTanValue")) )
Application.LogMessage( "RightSegKind: " + str(ivtInfo.Value("RightSegKind")) )
Application.LogMessage( "Constraints: " + str(ivtInfo.Value("Constraints")) )

The above example outputs the following information to the Script Editor in XSI:

#INFO : # of items: 9
#INFO : 260
#INFO : -0.266933333333
#INFO : -1.14285714286
#INFO : 7.0
#INFO : 0.834166666667
#INFO : 3
#INFO : 0.278055555556
#INFO : 1.19047619048
#INFO : 7.0

#INFO : Item1 = 260
#INFO : Item2 = -0.266933333333
#INFO : Item3 = -1.14285714286
#INFO : Item4 = 7.0
#INFO : Item5 = 0.834166666667
#INFO : Item6 = 3
#INFO : Item7 = 0.278055555556
#INFO : Item8 = 1.19047619048
#INFO : Item9 = 7.0

#INFO : Parameter: 0.834166666667
#INFO : LeftValue: 7.0
#INFO : RightValue: 7.0
#INFO : LeftTanParam: -0.266933333333
#INFO : LeftTanValue: -1.14285714286
#INFO : RightTanParam: 0.278055555556
#INFO : RightTanValue: 1.19047619048
#INFO : RightSegKind: 3
#INFO : Constraints: 260


This page was last modified 08:01, 31 Aug 2007.
This page has been accessed 5560 times.

© Copyright 2009 Autodesk Inc. All Rights Reserved. Privacy Policy | Legal Notices and Trademarks | Report Piracy