Part 1 – Finding Parameters (Introduction to the “Object Model”)

In Xsi, with scripting we have 4 different ways of getting the value of a parameter.

Say I have a sphere and I want find its X position. I can do any of the following:

print Application.GetValue("sphere.kine.global.posx")
print Application.Dictionary.GetObject("sphere.kine.local.posx").Value
print Application.ActiveSceneRoot.FindChild("sphere").Kinematics.Global.PosX.Value

You did ready correctly, I did say there are 4 ways though I’ve only shown 3. The fourth way is by using the FindObjects method. The reason I’ve left it out is it is a bit more complex to use than the others and in most cases you can get by by using one of the mentioned 3. But when you’re more comfortable coding in Xsi look it up in the SDK Guide.

The first method is by far the easiest. All you have to do to find what to put inbetween the brackets of the Application.GetValue().We can do this by changing the paramater we want in the viewport, seeing what the Script Editor Output says and changing it slightly. E.g: When I move my sphere along the X axis the Script Editor Outputs:

Application.SetValue("sphere.kine.global.posx", 3.435, "")

Now if I want to print the X Position of the sphere all I need to do is change the “SetValue” to “GetValue” and take out anything other than the sphere’s path:

Application.GetValue("sphere.kine.global.posx")

The first method is great for its ease but if I wanted to set the values of a few parameters on the sphere it would be quicker and easier to read in a script if we went with method 2 or 3. The reason for this is we can “get” the sphere and store it in a variable so we can access it whenever we want:

my_sphere = Application.Dictionary.GetObject("sphere")
or
my_sphere = Application.ActiveSceneRoot.FindChild("sphere")

The difference between method 2 and method 3 is that method 2 goes straight to the sphere object in memory and returns it. This method is by far the fastest of the three, Method 3 is the slowest because xsi does a search for an object named “sphere”. It searches under the Scene_Root, looking at the name of every object untill it finds one called “sphere”. For now we will go with the speedy method 2 but method 3 will come in quite handy later on.

So, back to the code. We now have the sphere object stored in the variable called “my_sphere”. This means we can set whatever parameter we wish quite easily. For example

Set sphere’s X position to 100:
my_sphere.Kinematics.Global.PosX.Value = 100

Set sphere’s Y Rotation to 20:
my_sphere.Kinematics.Global.RotY.Value = 20

Get the spheres Z Scale, devide it by two and store it in a variable called “half_scale” and finally set the sphere’s scale Z to out half_scale_z value:
scale_z = my_sphere.Kinematics.Global.SclZ.Value
half_scale_z = scale_z/2
my_sphere.Kinematics.Global.SclZ.Value = half_scale_z

Note: If you use Application.Dictionary.GetObject in your scene and the object you’re looking for doesn’t exist (or it you’re not sure) add a comma followed by False before your closing bracket. This tells Xsi NOT to throw an error if it can’t find the object. eg: If I want to try get an object named “cube” in my scene but I’m not sure if it exists in my scene or not I rune

my_cube = Application.Dictionary.GetObject(“cube”, False)    # This won’t throw an error if the object named “cube” doesn’t exist.

So I always write my Application.Dictionary.GetObject with a False at the end just incase 😉

2 thoughts on “Part 1 – Finding Parameters (Introduction to the “Object Model”)

  1. Pingback: Start Here!!! « Conquering the Code in Softimage Xsi

  2. Pingback: Start Here!!! | Conquering the Code in Softimage Xsi

Leave a comment