Part 3 – Finding parameters and their values with code

In some cases it can be easier and faster to find an object’s parameters and their values via code as opposed to having to look through the SDK Explorer (though it is very likely you will often use a combination of both).

As we already know, to gain access to a object we can do this:

sphere_obj = Application.Dictionary.GetObject("sphere", False)

From here we can either look for the parameters in the SDK Explorer or we can “loop” through them with code:

for param in sphere_obj.Parameters:
     print param.FullName

This will print the full path (FullName) to each parameter.

If we wanted the values too we could just print param.Value:

for param in sphere_obj.Parameters:
     print "Parameter:" + param.FullName
     print "Value:" + str(param.Value)

Now we can see exactly how to access each parameter and just to make sure its the right one we can check the value we see in Xsi (eg the Local X Position) compared to the value we see in the Script Editor Output (eg sphere.kine.local.posx)

The parameter’s path is made up of a combination of Objects followed by Properties and the finally the parameter’s ScriptName.

Image

In this case “sphere” is an object and “kine” and “local” are Properties.

An Object holds a collection of Properties and a Property holds a collection of Parameters.

You can loop through Properties just as you looped through Parameters with:

for prop in sphere_obj.Properties:
     print "Property:" + prop.FullName

Now that we know the Properties we can even loop through the Parameters of a specific Property:

for param in sphere_obj.Properties("visibility").Parameters:
     print "Parameter:" + param.ScriptName

From this we can narrow it down even further to:

print sphere_obj.Properties("visibility").Parameters("viewplaybackvis").Value

If there are other objects parented under the sohere and we only want to get those we can use:

for obj in sphere_obj.Children:
     print obj.FullName

which can be turned into (assuming you have an object named cone parented under your sphere_obj):

for prop in sphere_obj.Children("cone").Properties:
     print "Property:" + prop.FullName

And lastly we can call sphere_obj.NestedObjects. This returns any of the above mentioned things that are directly under the sphere_obj. I tend to use this as more of a last resort when calling Children, Properties or Parameters won’t work.

That said its about dinner time so I’m off home 😀

2 thoughts on “Part 3 – Finding parameters and their values with code

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

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

Leave a comment