Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Selects all points on object 'enveloped_mesh' which have a weight value for 'deformer' bigger than 'weight_threshold'.
''' SelectPointsByEnvelope '''
# --------------------------------
# SelectPointsByEnvelopeWeight
#
# Selects all points on object 'enveloped_mesh' which have a weight value for
# 'deformer' bigger than 'weight_threshold'.
#
# Installation:
# Put this file into C:/Users/<username>/Autodesk/Softimage_XX/Application/Plugins.
#
# Usage:
# Open the Script Editor (Alt+4), set the Script language to Python (either
# via the drop down directly at the top of the editor or File>Preferences).
# Enter the following line:
# Application.SelectPointsByEnvelopeWeight('enveloped_mesh', 'deformer', threshold)
# where enveloped_mesh is the name of the mesh to select points on,
# deformer is the name of the deformer the points should be weighted to,
# threshold is the weight threshold which needs to be met for the point to be selected (0-100%).
# Example:
# Application.SelectPointsByEnvelopeWeight('trooper_body', 'bone_hips', 80)
#
from win32com.client import constants as const
XSI = Application
def XSILoadPlugin(in_reg):
''' Registers Plugin and commands. '''
in_reg.Author = 'Ande'
in_reg.Name = 'SelectPointsByEnvelopeWeight'
in_reg.Email = 'schlchtwtrfrnt@gmail.com'
in_reg.URL = 'http://schlechtwetterfront.github.io/'
in_reg.Major = 1
in_reg.Minor = 0
in_reg.RegisterCommand('SelectPointsByEnvelopeWeight', 'SelectPointsByEnvelopeWeight')
return True
def XSIUnloadPlugin(in_reg):
''' Called on Unload. '''
return True
def SelectPointsByEnvelopeWeight_Init(in_ctxt):
'''Set up command and arguments.'''
command = in_ctxt.Source
command.Description = ''
command.ReturnValue = True
command.Arguments.Add('enveloped_mesh')
command.Arguments.Add('deformer')
command.Arguments.Add('weight_threshold', const.siArgumentInput, 80)
return True
def SelectPointsByEnvelopeWeight_Execute(enveloped_mesh, deformer, weight_threshold):
'''Select points based on deformer's weights.'''
enveloped_mesh = XSI.Dictionary.GetObject(enveloped_mesh.encode('utf-8'))
deformer = XSI.Dictionary.GetObject(deformer.encode('utf-8'))
envelope = enveloped_mesh.Envelopes(0)
deformer_index = 0
for index, envelope_deformer in enumerate(envelope.Deformers):
if envelope_deformer.Name == deformer.Name:
print envelope_deformer.Name
deformer_index = index
break
envelope_weights = envelope.Weights.Array[deformer_index]
XSI.DeselectAll()
XSI.SelectObj(enveloped_mesh)
XSI.ActivateVertexSelTool()
point_indices = []
for index, point_weight in enumerate(envelope_weights):
print 'index: {0} || weight: {1}'.format(index, point_weight)
if point_weight >= weight_threshold:
point_indices.append(index)
XSI.SelectGeometryComponents('{0}.pnt[{1}]'.format(enveloped_mesh.FullName, ', '.join([str(index) for index in point_indices])))
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment