Rename Tool
This script comes in script and plugin form. The plugin can be found here. gbRenamerPlugin
Here’s the script
#- gbRenamer_1.0 ------------------------------------------------------
#- wip - gbRenamer_004.pys
#- Date: 18.07.14
#- Author: Gareth Bell - garethb@outlook.com
#- This is just a simple string renaming tool
#- USE: - Select objects/passes etc you want to rename. Run it.
#- Options: Add prefix/suffix
#- Find/Replace with Case sensitivity toggle
#- Total rename
#-----------------------------------------------------------------------------
import win32com
c = win32com.client.constants
xsi = Application
root = xsi.ActiveSceneRoot
global newName
typeCase = ["Don't Force Case", "Don't Force Case", "lowercase", "lowercase", "UPPERCASE", "UPPERCASE"]
objectsColl = win32com.client.Dispatch( "XSI.Collection" )
objectsColl.AddItems (xsi.Selection)
def main():
global cpSet
cpSet = root.AddProperty("CustomProperty", False, "gbRenamer")
ppgLayout = cpSet.PPGLayout
ppgLayout.Language = "Python"
param = cpSet.AddParameter3("prefix", c.siString, "")
param = cpSet.AddParameter3("suffix", c.siString, "")
param = cpSet.AddParameter3("case", c.siBool, False, "", "", False)
param = cpSet.AddParameter3("find", c.siString, "")
param = cpSet.AddParameter3("replacement", c.siString, "")
param = cpSet.AddParameter3("rename", c.siString, "")
param = cpSet.AddParameter3("caseType", c.siString, typeCase[0])
#-- create layout
ppgLayout.AddGroup ("Force Case")
caseType = ppgLayout.AddEnumControl("caseType", typeCase, "Case", c.siControlCombo)
ppgLayout.EndGroup()
ppgLayout.AddGroup ("Add")
sPrefix = ppgLayout.AddItem("prefix", "Prefix", c.siString)
sSuffix = ppgLayout.AddItem("suffix", "Suffix", c.siString)
ppgLayout.AddSpacer()
ppgLayout.EndGroup()
ppgLayout.AddGroup ("Find/Replace")
sCase = ppgLayout.AddItem ("case", "Case-Sensitive", c.siControlBoolean)
sFind = ppgLayout.AddItem("find", "Find", c.siString)
sFind.SetAttribute (c.siUIContinue, True)
sReplacement = ppgLayout.AddItem("replacement", "Replace", c.siString)
ppgLayout.AddSpacer()
ppgLayout.EndGroup()
ppgLayout.AddGroup ("Complete Rename")
sRename = ppgLayout.AddItem("rename", "Rename", c.siString)
ppgLayout.AddSpacer()
ppgLayout.EndGroup()
inspectDialog = xsi.InspectObj (cpSet, "", "gbRenamer", c.siModal)
def forceCase():
lCase = xsi.Dictionary.GetObject ("gbRenamer.caseType").Value
return lCase
def getPrefix(eachObj):
global prefix
prefix = xsi.Dictionary.GetObject ("gbRenamer.prefix").Value
#print prefix
return prefix
def getSuffix(eachObj):
global suffix
suffix = xsi.Dictionary.GetObject ("gbRenamer.suffix").Value
#print suffix
return suffix
def caseSensitivity():
global caseSensitive
caseSensitive = xsi.Dictionary.GetObject ("gbRenamer.case").Value
return caseSensitive
def getFind(eachObj):
global find
find = xsi.Dictionary.GetObject ("gbRenamer.find").Value
if caseSensitivity() == True:
return find
else:
find = find.lower()
return find
return find
def getReplacement(eachObj):
global replacement
replacement = xsi.Dictionary.GetObject ("gbRenamer.replacement").Value
print replacement
return replacement
def getRename(eachObj):
global rename
rename = xsi.Dictionary.GetObject ("gbRenamer.rename").Value
return rename
def addPrefix(eachObj):
global newName
oldName = eachObj.Name
newName = prefix + oldName
eachObj.Name = newName
return newName
def addSuffix(eachObj):
global newName
oldName = eachObj.Name
newName = oldName + suffix
eachObj.Name = newName
return newName
def renameIt(eachObj):
global newName
oldName = eachObj.Name
newName = rename
eachObj.Name = newName
return newName
def replaceName(eachObj):
global newName
oldName = eachObj.Name
if caseSensitivity() == False:
oldName = oldName.lower()
newName = oldName.replace(find, replacement)
eachObj.Name = newName
return newName
#------- START HERE ------------------------
try:
main()
for eachObj in objectsColl:
if getPrefix(eachObj) != "":
addPrefix(eachObj)
if getSuffix(eachObj) != "":
addSuffix(eachObj)
if getFind(eachObj) != "":
if getReplacement(eachObj) != "":
replaceName(eachObj)
if getRename(eachObj) != "":
renameIt(eachObj)
if forceCase() == "lowercase":
eachObj.Name = eachObj.Name.lower()
elif forceCase() == "UPPERCASE":
eachObj.Name = eachObj.Name.upper()
else:
continue
xsi.DeleteObj(cpSet)
except:
xsi.DeleteObj(cpSet)
Move selected items to background partitions
This script will move selected items into background partitions of either the current pass or multiple selected passes
# Move selected objects to background partitions
# created by Gareth Bell
# original created in VBScript 28-11-11
# converted to Python 26-07-2012
# Description:
# This script will put the selected objects into either the current passes bg partitions or, if selected, multiple passes bg partitions
##################################
# To use: select objects and passes. Run.
##################################
import win32com
xsi = Application
#create collections to store objects
geoColl = win32com.client.Dispatch( "XSI.Collection" )
passesColl = win32com.client.Dispatch( "XSI.Collection" )
lightsColl = win32com.client.Dispatch( "XSI.Collection" )
selection = win32com.client.Dispatch( "XSI.Collection" )
selection.AddItems (xsi.Selection)
#sort selection into collections (objects, lights and passes)
for obj in selection:
if obj.type == "light":
lightsColl.AddItems (obj)
elif obj.type == "Pass":
passesColl.AddItems (obj)
else:
geoColl.AddItems (obj)
passCount = passesColl.Count
#decide if sorting is in only the current pass or multiple passes
if passCount > 0:
for eachPass in passesColl:
print str(geoColl) + " has/have been put into the background partition in " + str(eachPass.name)
xsi.MoveToPartition(str(eachPass) + ".background_objects_partition", geoColl, eachPass)
print str(lightsColl) + " has/have been put into the background partition in " + str(eachPass.name)
xsi.MoveToPartition(str(eachPass) + ".background_lights_partition", lightsColl, eachPass)
else:
currentPass = xsi.ActiveProject.ActiveScene.ActivePass
print str(geoColl) + " has/have been put into the background partition in the current pass"
xsi.MoveToPartition(str(currentPass) + ".background_objects_partition", geoColl, currentPass)
print str(lightsColl) + " has/have been put into the background partition in the current pass"
xsi.MoveToPartition(str(currentPass) + ".background_lights_partition", lightsColl, currentPass)
Convert Models to Nulls
This small script will convert selected models into nulls.
import win32com
xsi = Application
objs = win32com.client.Dispatch( "XSI.Collection" )
objs.AddItems (xsi.Selection)
for i in objs:
if i.Type == "#model":
newNull = xsi.GetPrim("null", str(i) + "_null", "", "") #create null
xsi.MatchTransform(newNull, i, "siSRT") #match it's transforms to the model
for eachChild in i.Children: #parent model's children to null
xsi.ParentObj(newNull, eachChild)
try:
for eachGroup in i.Groups: #move groups to nulls parent
xsi.CopyPaste (eachGroup,"", newNull.Parent, 1)
except:
print ""
try:
xsi.ParentObj (i.Parent, newNull) #parent new null to original models parent
except:
print ""
xsi.DeleteObj (i) #Delete original model
else:
print "Select models only"
mia2vray material converter
This small script will swap selected materials mia shaders into vraymtrl shaders. This script was inspired by Paul Driesen’s script for MayaÂ
#mia2vray converter
#author: gareth bell
#date: 15-10-2012
#This script will break the back of converting mia shaders in selected materials into vrayMtls
#Use: Select materials. Run
import win32com.client
import siutils
from siutils import si
from siutils import C
xsi = Application
coll = win32com.client.Dispatch( "XSI.Collection" )
vrayMaterials = win32com.client.Dispatch( "XSI.Collection" )
#############################################
def traverse( s, coll ):
for p in s.Parameters:
if p.Source and p.Source.IsClassOf( C.siShaderParameterID ):
coll.Add( p.Source.Parent )
traverse( p.Source.Parent, coll )
for l in s.TextureLayers:
for y in l.Parameters:
if y.Source and y.Source.IsClassOf( C.siShaderParameterID ):
coll.Add( y.Source.Parent )
traverse( y.Source.Parent, coll )
############################################
def createVrayShader (eachShader):
vrayMaterial = xsi.CreateShaderFromProgID("Softimage.VRayMtl.1.0", mat, "VRayMtl")
vrayMaterials.AddItems (vrayMaterial)
miaName = eachShader.name
vrayName = vrayMaterial.FullName
#match diffuse colour
xsi.SetValue( (str(vrayName) + ".diffuse_color.red"), eachShader.diffuse.red.value, "")
xsi.SetValue( (str(vrayName) + ".diffuse_color.green"), eachShader.diffuse.green.value, "")
xsi.SetValue( (str(vrayName) + ".diffuse_color.blue"), eachShader.diffuse.blue.value, "")
#match reflection colour
xsi.SetValue( (str(vrayName) + ".reflection_color.red"), eachShader.refl_color.red.value, "")
xsi.SetValue( (str(vrayName) + ".reflection_color.green"), eachShader.refl_color.green.value, "")
xsi.SetValue( (str(vrayName) + ".reflection_color.blue"), eachShader.refl_color.blue.value, "")
#match refraction colour
xsi.SetValue( (str(vrayName) + ".refr_color.red"), eachShader.refr_color.red.value, "")
xsi.SetValue( (str(vrayName) + ".refr_color.green"), eachShader.refr_color.green.value, "")
xsi.SetValue( (str(vrayName) + ".refr_color.blue"), eachShader.refr_color.blue.value, "")
#match roughness
xsi.SetValue( (str(vrayName) + ".roughness"), eachShader.diffuse_roughness.value, "")
#match gloss
xsi.SetValue( (str(vrayName) + ".refr_glossiness"), eachShader.refr_gloss.value, "")
#match IOR
xsi.SetValue( (str(vrayName) + ".refr_ior"), eachShader.refr_ior.value, "")
#match anisotropy
a = eachShader.anisotropy.value
#equation for getting anisotropy values in range 0 to 10 (mia_shader) converted to -1 to 1 (vray_shader) is (a/5.0)-1)
xsi.SetValue( (str(vrayName) + ".brdf_anisotropy"), (a/5.0)-1.0)
#match rotation
xsi.SetValue( (str(vrayName) + ".brdf_rotation"), eachShader.anisotropy_rotation.value, "")
#match fresnel
fres = eachShader.brdf_fresnel.value
if fres == True:
xsi.SetValue( (str(vrayName) + ".reflection_enable_fresnel"), False, "")
else:
xsi.SetValue( (str(vrayName) + ".reflection_enable_fresnel"), True, "")
inputCnx = win32com.client.Dispatch( "XSI.Collection" )
cnxPoint = win32com.client.Dispatch( "XSI.Collection" )
for p in eachShader.Parameters:
if p.Source and p.Source.IsClassOf( C.siShaderParameterID ):
inputCnx.Add (p.Source.Parent)
cnxPoint.Add (p)
for i in range (0, inputCnx.Count):
#print inputCnx(i)
#print cnxPoint(i).Name
if cnxPoint(i).Name == "diffuse":
vrayCnxPoint = "diffuse_color"
elif cnxPoint(i).Name == "refl_color":
vrayCnxPoint = "reflection_color"
elif cnxPoint(i).Name == "refr_color":
vrayCnxPoint == "refr_color"
elif cnxPoint(i).Name == "roughness":
vrayCnxPoint == "diffuse_roughness"
elif cnxPoint(i).Name == "refr_glossiness":
vrayCnxPoint == "refr_gloss"
elif cnxPoint(i).Name == "refr_ior":
vrayCnxPoint == "refr_ior"
elif cnxPoint(i).Name == "anisotropy":
vrayCnxPoint == "brdf_anisotropy"
elif cnxPoint(i).Name == "brdf_rotation":
vrayCnxPoint == "anisotropy_rotation"
xsi.SIConnectShaderToCnxPoint( (inputCnx(i).out) , str(vrayName) + "." + str(vrayCnxPoint))
#match name to mia_name
xsi.SetValue((str(vrayName) + ".Name"), "VRay" + str(eachShader.name)[3:])
#############################################################
#############################################################
prefs = xsi.Preferences
#get commandlog prefs
origPrefs = prefs.GetPreferenceValue ("scripting.cmdlog")
#turn log off
prefs.SetPreferenceValue ("scripting.cmdlog", False)
# get material
for mat in xsi.Selection:
traverse( mat, coll )
coll.Unique = True
for eachShader in coll:
if "Softimage.mia_material_phen.1.0" in eachShader.ProgID:
print ""
elif "mentalray.mia_material_x.1.0" in eachShader.ProgID:
print ""
else:
coll.Remove( eachShader )
for eachShader in coll:
createVrayShader (eachShader)
#get mia shaders output connections and plug them into the newly created vRay shader
for s in range (0, coll.count):
targets = coll(s).GetShaderParameterTargets("")
for eachTarget in targets:
xsi.SIConnectShaderToCnxPoint(str(vrayMaterials(s)) + ".out" , eachTarget, False)
#delete mia shader
xsi.DeleteObj (coll(s))
#empty collections
vrayMaterials.RemoveAll()
coll.RemoveAll()
#restore original log prefs
prefs.SetPreferenceValue ("scripting.cmdlog", origPrefs)
extrudeMultiCurve
It came to my attention from a colleague today that there isn’t an easy way to extrude along multiple curves in Softimage. So I knocked up this little script for her.
#extrudeMultiCurves_001
#To Use:
# 1) Select the curves you want to extrude along.
# 2) Run script
# 3) Pick the profile curve
import win32com
xsi = Application
#collect all curves
extCurves = win32com.client.Dispatch( "XSI.Collection" )
extCurves.AddItems (xsi.Selection)
#pick profile curve
profileCurve = xsi.PickElement ("", "Pick Profile Curve")
#loop through all extCurves and extrude along profileCurve
for i in range (0, extCurves.count):
xsi.ApplyGenOp("Extrusion", "MeshSurface", str(profileCurve(2)) + ";" + str(extCurves(i)), 3, "siPersistentOperation", "siKeepGenOpInputs", "")
Delete Empty Partitions
I like to keep my passes tidy so this little script just strips out any empty partitions on selected passes.
# USE: Select passes and run the script
import win32com
xsi = Application
selectedPasses = win32com.client.Dispatch( "XSI.Collection" )
selectedPasses.AddItems (xsi.Selection)
#--------------------------------------------------------------
#--------------------------------------------------------------
#--------------------------------------------------------------
def stripPass(eachPass):
partitionsColl = win32com.client.Dispatch( "XSI.Collection" )
for eachPartition in eachPass.Partitions:
partitionsColl.AddItems (eachPartition)
#-- Remove background partitions from the collection ---------------------
partitionsColl.RemoveItems (partitionsColl[0])
partitionsColl.RemoveItems (partitionsColl[0])
for eachPartition in partitionsColl:
if eachPartition.Members.Count == 0:
print str(eachPartition) + " is empty :: Deleted ::"
xsi.DeleteObj (eachPartition)
#--------------------------------------------------------------
#--------------------------------------------------------------
for eachPass in selectedPasses:
stripPass(eachPass)
