Wednesday, January 25, 2012

Selecting And Parenting (Project #1)

The Big Picture:
I was tasked with writing a script in Python for our Softimage pipeline that allows users to inject a model from one scene into another.

The Problem:
If a user doesn't have anything selected specifically, I need to select just the objects in the scene root but not all their children.


The Solution:
After much searching and trial and error, I finally found this bit of code did the trick:
xsi = Application
log = Application.LogMessage
sel = win32com.client.Dispatch( "XSI.Collection" )
if xsi.Selection.Count:
 if xsi.Selection[0].FullName == "Scene_Root":
  list = xsi.ActiveSceneRoot.Children
  for child in list:
   sel.Add( child )
 else:
  for x in xsi.Selection:
   sel.Add(x)
else:
 log( "Nothing was selected. Using the entire scene!" )
 
 list = xsi.ActiveSceneRoot.Children
 for child in list:
  sel.Add( child )
For the purposes of this simple script, this was exactly what I needed.

What I Discovered:
Trying to select everything simply using
Application.SelectAll()
will grab everything in the scene except the "Scene Root" but that also means it's grabbing the children nodes and their children, etc. I was having to export a model to be imported into a scene later in the process -- so parenting all the selected objects under a newly created "Model" node was a problem using this method. What would happen is a flat list of objects being placed under the new node, rather than keeping any hierarchy in place.

Thursday, January 19, 2012

Softimage Plug-ins (Using Python)

The Big Picture:
I need to understand how to create a Command in Softimage.

The Problem:
I've never used it before! I need to understand the fundamentals.

The Solution:
Follow the steps below to create a basic new Command:

  1. Go to "File / Plugin Manager".
  2. Select the "Plug-ins" tab.
  3. Choose "File... / New / Command".
  4. In the SDK Wizard window that pops up, select the "Plug-in Definition" tab.
  5. Set the "Command Name" to the name you'd like to use to call this script.
  6. The "Plug-in" Name should automatically change - you can leave this alone.
  7. Be sure the "Coding Language" is set to Python.
  8. For the sake of explanation, click the "Generate Code" at the bottom of this window. It will create a template of code for you to begin editing.

The code you want executed needs to be placed under the
YourPluginName_Execute()
function.

To test that you've set everything up correctly, open the script editor in Softimage and call your new Command by simply typing:
Application.YourCommandName()

You can call this Command from any other script just like any other native Softimage Command.


What I Discovered:
Creating a Command/Plug-in is pretty straightforward and simple. There weren't really any caveats that I encountered so far when using them, but I'll be sure to make an update if I find one down the line.