Scripting – Applying an ICE compound to multiple objects

UPDATE: Script updated to work in 2013

Here’s a script for applying an ICE compound to many objects in one go.

The script pops up a browser where you select a compound, and then the selected compound is applied to all selected objects (or, if a group is selected, to all members of the group.

I posted something similar before, but that was part of an add-on that adds new menu commands for applying ICE operators.

from siutils import si		# Application
if Application.Version().split('.')[0]>= "11":
	    si = si()                   # win32com.client.Dispatch('XSI.Application')

from siutils import log		# LogMessage
from siutils import C		# win32com.client.constants
from siutils import disp	# win32com.client.Dispatch

siut = disp('XSI.Utils')
sifact = disp('XSI.Factory')
siuitk = disp('XSI.UIToolkit')
sisel = si.Selection

# Pop up a browser to select a compound
def getCompound():
	initialDir = siut.BuildPath( si.InstallationPath( C.siUserPath ), "Data", "Compounds" )

	oFileBrowser = siuitk.FileBrowser
	oFileBrowser.DialogTitle = "Select compound to apply"
	oFileBrowser.InitialDirectory = initialDir
	oFileBrowser.Filter = "All Files (*.*)|*.*||"

	return oFileBrowser.FilePathName

# Apply op to 
# - the selected objects
# OR
# - the members of a selected group
def getTargetObjects():
	objects = disp( "XSI.Collection" )

	if sisel.Count == 0:
		log( "Please select either some objects or a group" )
	elif sisel(0).IsClassOf( C.siGroupID ):
		objects = sisel(0).Members
		objects = sisel

	return objects

# Do it...
objects = getTargetObjects()	
sCompound = getCompound()

if sCompound != "" and objects.Count > 0:
	for o in objects:
		si.ApplyICEOp( sCompound, o.FullName )

2 thoughts on “Scripting – Applying an ICE compound to multiple objects

  1. Was native ice at one stage intending to do this to groups of objects?
    ie, one icetree applied to many objects? (without explicitly defining/ selecting individual objects)

  2. # ERROR : Traceback (most recent call last):
    # File “”, line 12, in
    # sisel = si.Selection
    # AttributeError: ‘unicode’ object has no attribute ‘Selection’
    # – [line 12]

    I get this error when I run it. Any idea what is going on?
    Maybe there’s a issue when copying the code from the website?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s