Python Object Model Examples (XSISDK)
See Object Model Reference - Additional Examples for guidelines about adding Python examples to this page.
[edit]
Python Example: Creating a Clip
#
# This example demonstrates how to create a Clip containing the static
# values of the local position of an object.
#
oRoot = Application.ActiveSceneRoot
oCube = oRoot.AddGeometry( "Cube", "MeshSurface" )
# Creating the first animation source
sParams = "cube.kine.local.posx,cube.kine.local.posy,cube.kine.local.posz"
oSource = Application.StoreAction( oRoot, sParams, 1, "StoredStaticPose", 1, 1, 5, 0, 0)
# Creating the first clip
oClip = Application.AddClip( oRoot, oSource )
Application.LogMessage( "First created clip " + oClip.FullName )
# Creating the second animation source
oCube.Parameters("posx").Value = 3.0
oSource2 = Application.StoreAction( oRoot, sParams, 1, "StoredStaticPose", 1, 7, 9, 0, 0 )
# Creating the second clip
oClip2 = Application.AddClip(oRoot, oSource2)
Application.LogMessage("Second created clip " + oClip2.FullName)
# Expected results:
#INFO : First created clip Mixer.Mixer_Anim_Track.StoredStaticPose_Clip
#INFO : Second created clip Mixer.Mixer_Anim_Track1.StoredStaticPose1_Clip
[edit]
Python Example: Accessing Geometry
#
# This example demontrates how to get position of a point at a specific time frame
#
# Import the constants
from win32com.client import constants as c
import sys, types
Application.NewScene("", 0)
oGrid = Application.ActiveSceneRoot.AddGeometry( "Grid", "MeshSurface" )
Application.SetValue (oGrid.Name + ".polymsh.geom.subdivu", 1)
Application.SetValue (oGrid.Name + ".polymsh.geom.subdivv", 1)
Application.Scale( oGrid, 0.25, 0.25, 0.25, c.siAbsolute, c.siParent, c.siObj, c.siXYZ)
startTimeInSeconds = 5 / 29.97
duration = startTimeInSeconds * 2
# Start at frame 5 && last 100 frames
oClip = oGrid.ActivePrimitive.Geometry.SaveShapeKey(
startTimeInSeconds,
duration,
c.siShapeAbsoluteReferenceMode,
c.siShapeInstanceOnlyMode,
"Clip", ( 0,1,2,3),
( -4,0,-4,
-4,0, 4,
4,0, 0,
4,0, 4 ))
# Frame 3 should be the original grid
oPoints = oGrid.ActivePrimitive.GetGeometry2(3,c.siConstructionModeSecondaryShape).Points
oPos = oPoints[2].Position
Application.LogMessage( "%f,%f,%f" % ( oPos.X,oPos.Y,oPos.Z ) )
# Frame 10 should the modified grid in the clip
oPoints = oGrid.ActivePrimitive.GetGeometry2(10).Points
oPos = oPoints[2].position
Application.LogMessage( "%f,%f,%f" % ( oPos.X,oPos.Y,oPos.Z ) )
# Expected results:
#INFO : 4.000000,0.000000,-4.000000
#INFO : 4.000000,0.000000,0.000000
[edit]
Python Example: Setting and Getting FCurve Keys
# # This example demonstrates how to set an fcurve on the posx parameter # and then how to access the keys through the FCurveKey object # Application.NewScene( "", 0 ) oRoot = Application.ActiveProject.ActiveScene.Root oNull = oRoot.AddNull() oPosX = oNull.posx # Create and connect an fcurve to the position x oFCurve = oPosX.AddFCurve2( [1, 10, 50, 0, 100, 10] ) # Set the zero slopes on the key tangents oFCurve.SetKeyTangents( [ -10.5, 0, 10.5, 0, -10.5, 0, 10.5, 0, -10.5, 0, 10.5, 0 ]) # Get the keys on the fcurve for oFCKey in oFCurve.Keys : Application.LogMessage( "oFCKey[" + str(oFCKey.Index) + "] at frame " + str(oFCKey.Time) + " = " + str(oFCKey.Value) ) # Expected results: #INFO : oFCKey[0] at frame 1.0 = 10.0 #INFO : oFCKey[1] at frame 50.0 = 0.0 #INFO : oFCKey[2] at frame 100.0 = 10.0
This page was last modified 16:58, 21 Dec 2006.
This page has been accessed 2264 times.

