Last active
August 29, 2015 14:11
-
-
Save Schlechtwetterfront/73124aa70db53398383c to your computer and use it in GitHub Desktop.
Selects all points on object 'enveloped_mesh' which have a weight value for 'deformer' bigger than 'weight_threshold'.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' 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