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:
For the purposes of this simple script, this was exactly what I needed.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 )
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.