Skip to content

Instantly share code, notes, and snippets.

@tcrowson
Created November 10, 2015 21:15
Show Gist options
  • Save tcrowson/01f19bd19b391d710d34 to your computer and use it in GitHub Desktop.
Save tcrowson/01f19bd19b391d710d34 to your computer and use it in GitHub Desktop.
Softimage - For selected model nulls, finds renderable items and groups them according to their source models.
# Group Meshes By Model
# DESCRIPTION
# - Adds a new command, GroupMeshesByModel(), which can be called from a key assignment or shelf button.
# - For selected model nulls, finds renderable items and groups them according to their source models.
# - Groups the following: meshes, pointclouds, instances, and hair.
# INSTALLATION
# This is a self-installing plugin, so place it in your user scripts
# or similar folder in the workgroup of your choosing.
# USAGE
# Select the model nulls you want to effect and run the command.
import win32com.client
from win32com.client import constants
def XSILoadPlugin( in_reg ):
in_reg.Author = "Tim Crowson"
in_reg.Name = "GroupMeshesByModel"
in_reg.Major = 1
in_reg.Minor = 0
in_reg.RegisterCommand("GroupMeshesByModel","GroupMeshesByModel")
return True
def XSIUnloadPlugin( in_reg ):
strPluginName = in_reg.Name
Application.LogMessage(str(strPluginName) + str(" has been unloaded."),constants.siVerbose)
return True
def GroupMeshesByModel_Init( in_ctxt ):
oCmd = in_ctxt.Source
oCmd.Description = ""
oCmd.ReturnValue = True
return True
def GroupMeshesByModel_Execute( ):
Application.LogMessage("GroupMeshesByModel_Execute called",constants.siVerbose)
selectedModels = [x for x in Application.Selection if x.Type == "#model"]
groups = [ str(x) for x in Application.FindObjects("", "{9D0673C2-6741-11D1-BE9F-00A024EE478D}")]
for model in selectedModels:
# Get or create the group
grpName = "GEO_%s"%model
grpFullName = "%s.%s"%(model.parent, grpName)
if model.ModelKind == 0 and grpFullName in groups:
grp = Application.Dictionary.GetObject(grpFullName)
else:
grp = Application.ActiveProject2.ActiveScene.Root.AddGroup(None, grpName)
# Add polymeshes
for y in model.FindChildren("", "polymsh"):
grp.AddMember(y, False)
# Add pointclouds
for y in model.FindChildren("", "pointcloud"):
grp.AddMember(y, False)
# Add instances
for y in model.FindChildren("", "#model"):
if y.ModelKind == 2:
grp.AddMember(y, False)
# Add hair
for y in model.FindChildren("", "hair"):
grp.AddMember(y, False)
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment