Adding your ICE operators to menus


The User Tools menu in an ICE Tree view has an Add Operator to Menu command that adds your compounds to menus, so you can apply them to the selected object. “Add Operators to Menu” is implemented in VBScript in %XSI_HOME%\Addons\ICEUserTools\Application\Plugins\ICEUserTools.vbs.

Unfortunately, this command wasn’t updated after 2011 Advantage Pack, so it doesn’t know about the new ICE toolbar and menu structure.

So, here’s a Python version that adds ICE operators to either the Particles > Create or Deform > Create menus in the ICE toolbar. When you apply the operators, they will be applied to all selected objects.

http://dl.dropbox.com/u/12898205/AddICEOperatorsToMenus.xsiaddon

The addon adds a “PSS Add Operators to Menu” command to the User Tools menu of the ICE Tree view, so it does add a bit of clutter (since I cannot programmatically remove the original Add Operators to Menu command).

To add operators to menus:

  1. Export your compound.
  2. In the ICE Tree view, click User Tools > PSS Add Operator to Menu.
  3. Type the name of the xsicompound file (without the .xsicompound extension).
  4. The next time you open the menu, it will be dynamically updated to include a command that applies your operator (with ApplyICEOp) to all selected objects.

See below the fold for the plugin code.

# ICEOperators2Plugin
# Initial code generated by Softimage SDK Wizard
# Executed Wed Aug 17 11:32:10 EDT 2011 by blairs
# 
import win32com.client
from win32com.client import constants

null = None
false = 0
true = 1

def XSILoadPlugin( in_reg ):
	in_reg.Author = "blairs"
	in_reg.Name = "ICEOperators2Plugin"
	in_reg.Major = 1
	in_reg.Minor = 0

	in_reg.RegisterProperty("pssICEOperators2")
	
#	in_reg.RegisterMenu(constants.siMenuTbICEParticlesCreateID,"pssICEParticlesCreateCustom_Menu",false,true)
	in_reg.RegisterMenu(constants.siMenuTbICEParticlesCreateID,"pssICEParticlesCreateCustom_Menu",False,True)
	in_reg.RegisterMenu(constants.siMenuTbICEDeformCreateID,"pssICEDeformCreateCustom_Menu",False,True)
	
#	in_reg.RegisterMenu( constants.siMenuICENodeContextID,"pssToolsContextMenu_Menu",False,True )
	in_reg.RegisterMenu( constants.siMenuICEViewToolsID,"pssToolsMenu_Menu",False,False )

	#RegistrationInsertionPoint - do not remove this line

	return true

def XSIUnloadPlugin( in_reg ):
	strPluginName = in_reg.Name
	Application.LogMessage(str(strPluginName) + str(" has been unloaded."),constants.siVerbose)
	return true


#-----------------------------------------------------------------------
# Custom property used as a preference
#-----------------------------------------------------------------------

def pssICEOperators2_Define( in_ctxt ):
	oCustomProperty = in_ctxt.Source
	oCustomProperty.AddParameter2("CreateParticles",constants.siString,"",null,null,null,null,constants.siClassifUnknown,constants.siPersistable + constants.siKeyable)
	oCustomProperty.AddParameter2("CreateDeform",constants.siString,"",null,null,null,null,constants.siClassifUnknown,constants.siPersistable + constants.siKeyable)
	oCustomProperty.AddParameter2("CreatePrimitive",constants.siString,"NotImplemented",null,null,null,null,constants.siClassifUnknown,constants.siPersistable + constants.siKeyable)
	return true

# Tip: Use the "Refresh" option on the Property Page context menu to 
# reload your script changes and re-execute the DefineLayout callback.
def pssICEOperators2_DefineLayout( in_ctxt ):
	oLayout = in_ctxt.Source
	oLayout.Clear()
	
	oLayout.AddStaticText( 'To add ICE operators to a menu, enter a comma-separated list of ICE compounds.' )
	oLayout.AddStaticText( 'Use the name of the compound (without the .xsicompound extension).' )
	
	oLayout.AddSpacer( 20 )
	
	oLayout.AddGroup( "ICE>Particles>Create" )
	oItem = oLayout.AddItem("CreateParticles", "Operators" )
	oItem.SetAttribute( "NoLabel", True )
	oLayout.EndGroup()

	oLayout.AddSpacer( 2 )

	oLayout.AddGroup( "ICE>Deform>Create" )
	oItem = oLayout.AddItem("CreateDeform", "Operators")
	oItem.SetAttribute( "NoLabel", True )
	oLayout.EndGroup()

	oLayout.AddSpacer( 2 )
	
	oLayout.AddGroup( "Model>Primitive>Get" )
	oItem = oLayout.AddItem("CreatePrimitive", "Operators")
	oItem.SetAttribute( "NoLabel", True )
	oLayout.EndGroup()

	return true


#-----------------------------------------------------------------------
# New menu item for the the User Tools menu in the ICE Tree view
#-----------------------------------------------------------------------

def pssToolsMenu_Menu_Init( in_ctxt ):
	oMenu = in_ctxt.Source
	oMenu.AddSeparatorItem()
	oMenu.AddCallbackItem( "PSS Add Operators to Menus","pssOnICEOperatorsClicked" )
	return true

def pssOnICEOperatorsClicked( in_ctxt ):
	CheckExistence( "preferences.pssICEOperators2" )
	oView = Application.Desktop.ActiveLayout.CreateView("Property Panel", "PSS_ICEOperators2")
	oView.SetAttributeValue( "targetcontent", "preferences.pssICEOperators2" )
	oView.Resize( 500, 300 )
	return true


#-----------------------------------------------------------------------
# Dynamically build the custom menu items for the ICE operators
#-----------------------------------------------------------------------

def pssICEDeformCreateCustom_Menu_Init( in_ctxt ):
	oMenu = in_ctxt.Source
	
	# Add section divider
	oPPG = Application.GetValue ("preferences.pssICEOperators2")
	items = oPPG.CreateDeform.Value.split(',')
	if len(items[0]) > 0:
		# Add section divider
		oMenu.AddSeparatorItem()

		# Add custom menu items
		for i in items:
			oMenu.AddCallbackItem( i, "pssOperatorClicked" )
		
	return true
	
	
def pssICEParticlesCreateCustom_Menu_Init( in_ctxt ):
	oMenu = in_ctxt.Source
	oPPG = Application.GetValue ("preferences.pssICEOperators2")
	items = oPPG.CreateParticles.Value.split(',')
	if len(items[0]) > 0:
		# Add section divider
		oItem = oMenu.AddItem( "Custom", 4 )
		oItem.SetBackgroundColor(178,191,194)

		# Add custom menu items
		for i in items:
			oMenu.AddCallbackItem( i, "pssOperatorClicked" )
		
	return true


#-----------------------------------------------------------------------
# Callback that applies the ICE operator
#-----------------------------------------------------------------------

def pssOperatorClicked( in_ctxt):
	oString = in_ctxt.source
	Application.LogMessage( 'pssOperatorClicked' )
	Application.LogMessage( oString )
	for i in range(0,Application.Selection.Count):
		oObj = Application.Selection(i)
		Application.ApplyICEOp( oString, oObj.FullName )

	return true

#-----------------------------------------------------------------------
# Check that the custom preference is in place
#-----------------------------------------------------------------------


def CheckExistence(in_str):
	oPrefs = Application.Preferences
	oLog = oPrefs.GetPreferenceValue ("scripting.cmdlog")
	oMsg = oPrefs.GetPreferenceValue ("scripting.msglog")
	oPrefs.SetPreferenceValue( "scripting.cmdlog", False )
	oPrefs.SetPreferenceValue( "scripting.msglog", False )

	try:
		oObj = Application.Dictionary.GetObject( in_str )
	except:
		Application.RefreshCustomPreferences()

	oPrefs.SetPreferenceValue( "scripting.cmdlog", oLog )
	oPrefs.SetPreferenceValue( "scripting.msglog", oMsg )

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s