Categories
softimage

Softimage: Automatic Symmetry Mapping Template

If you do rigging in Softimage you probably know when trying to Mirror Weights it only pays attention to the last created Symmetry Mapping Template for that model. There’s no interface to append to or join mapping templates. It gets annoying having to recreate them and verify that Soft guessed all the correct symmetrical equivalents, so…


The following Python script iterates through your selected enveloped objects, creates SymmetryMaps if one doesn’t exist, and then goes through their envelope deformers and appends them to the SymmetryMappingTemplate for that model based on the naming convention of prefixing “L_” for left-side and “R_” for right-side objects.

It assumes the following: (and maybe in the future I’ll make the code smarter…)
– Your selected objects all have envelopes.
– Your left-side objects begin with “L_” and the right-side with “R_”.
– All your selected objects belong to the same Model.
– That you don’t have more than one SymmetryMappingTemplate under your model. (It will append to the first one found under the model, and create one if one isn’t found.) I recommend not having one to start with.

Make yourself a button with this:

xsi = Application
lm = xsi.LogMessage
from win32com.client import constants as c
import win32com.client

objects = win32com.client.Dispatch( "XSI.Collection" )
objects.AddItems(xsi.Selection)

# Iterate through selection
for envObj in objects:
	lm( "Iterating through: "+envObj.FullName, c.siVerbose )
	
	# Create a SymmetryMappingTemplate if needed.
	oSymmetryMapTemplate = xsi.Dictionary.GetObject( envObj.Model.Name+".SymmetryMappingTemplate", False )
	if not oSymmetryMapTemplate:
		oSymmetryMapTemplate = xsi.CreateSymmetryMappingTemplate(envObj, False, 0, False)
		lm( "Symmetry Mapping Template not found; created one.", c.siVerbose )



	# Create a SymmetryMap if it doesn't exist.
	sMapCls = envObj.ActivePrimitive.Geometry.Clusters("SymmetryMapCls")

	found = False
	if sMapCls:
		sMap_props = sMapCls.LocalProperties
		for eachProp in sMap_props:
			if eachProp.Type == "map" and not found:
				sMap = eachProp
				found = True
				lm( "Found SymmetryMap: "+sMap.FullName, c.siVerbose )
	
	if not found:
		lm( "SymmetryMap not found; created one.", c.siVerbose )
		#sMap = xsi.CreateSymmetryMap("", envObj, "Symmetry_Map")(0)
		sMap = xsi.CreateSymmetryMap("", envObj, "", "")(0)



	# Add envelope deformers to template by name:
	i = xsi.GetNumMappingRules( oSymmetryMapTemplate ) + 1
	oppositeNaming = {"L_":"R_", "R_":"L_"}
	envelope = envObj.Envelopes(0)
	deformers = envelope.Deformers
	for eachDef in deformers:
		name_A = eachDef.Name

		if name_A[:2] in oppositeNaming.keys():
			name_B = name_A.replace(name_A[:2], oppositeNaming.get(name_A[:2]), 1)

			xsi.AddMappingRule( oSymmetryMapTemplate, name_A, name_B, i)
			lm( "Adding Mapping Rule #"+str(i)+": "+name_A+" <--> "+name_B, c.siVerbose )
			i += 1

xsi.SelectObj(objects)

I might update the code in the future to support multiple models and check if an entry in the template has been added already, but for now this above will have to do.

Hope it’s useful to somebody! 🙂

One reply on “Softimage: Automatic Symmetry Mapping Template”

Leave a Reply