Part 2 – Applying a command to multiple objects

We start off in pretty much the same manner as Part 1 (Easily turn echoed commands into buttons.) by opening the script editor (Alt+4) and clearing its previous output.

In this example I have a few cubes in my scene that I want to be able to hide and show with the click of a button. This is really easy to do 😉

I haven’t changed the names of the cubes, they are called “cube1”, “cube2” etc.

So now same as in Part 1 I manually do what I want and then copy the echoed commands.

So, first I select one cube. Then I press the “h” key to toggle its visibility.

The script editor echoes the commands:

Application.SelectObj("cube1", "", True)
Application.ToggleVisibility("", "", "")

This is great but if I were to put this into a button it would only toggle the visibility of “cube1”, I want to be able to do All the objects who’s names start with “cube”.

This is done with this little guy: * (an asterix or wildcard). This guy basically tells Xsi to look for anything who’s name starts with “cube”, regardless of what it ends with.

So when I run the commands

Application.SelectObj("cube*", "", True)
Application.ToggleVisibility("", "", "")

All the cubes in the scene are hidden, and when i run it again they are unhidden. When you want to edit a command, copy it from the bottom half of the script editor (“output”) to the top half (“editor”). In here you can change the commands as you please and test them too by pressing F5 or clicking the run button.

When you are happy with your code, select it and drag it onto a toolbar (you can turn code in from both the output or the editor section of the script editor, though in this case we are dragging from the editor section).

This asterix trick can be applied to many Xsi commands, here are a few more examples that would work:

To assign a material to all the cubes, after assigning manually the command in the script editor output is:

Application.AssignMaterial("Sources.Materials.DefaultLib.MyMaterial,cube1", "siLetLocalMaterialsOverlap")

so I change it to:

Application.AssignMaterial("Sources.Materials.DefaultLib.MyMaterial,cube*", "siLetLocalMaterialsOverlap")

If I want to turn off the render visibility for all the cubes, manually I get:

Application.SetValue("cube1.visibility.rendvis", False, "")

which I change to:

Application.SetValue("cube*.visibility.rendvis", False, "")



and so on 🙂

2 thoughts on “Part 2 – Applying a command to multiple objects

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

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

Leave a comment