Last active
October 1, 2015 14:59
-
-
Save tcrowson/c7028346e7d00e1ba584 to your computer and use it in GitHub Desktop.
Modo 901 command for duplicating the selected morph map
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
# Command for duplicating the selected morph. | |
# Tim Crowson, June 2015 | |
import lx | |
import lxu | |
import lxifc | |
import modo | |
def ensure_mesh_selection(): | |
''' Return selected meshes, False if none ''' | |
meshes = [x for x in modo.Scene().selected if x.type == 'mesh'] | |
if len(meshes) == 0: | |
modo.dialogs.alert('FAILED', | |
'Please select a mesh.', | |
'warning') | |
return False | |
return meshes | |
def get_selected_vmaps(map_type): | |
''' Return a list of selected weight map names ''' | |
# Get selected weight map. | |
# Hopefully in SP2 we'll get a wrapper for this. | |
selected_vmap_names = [] | |
sel_serv = lx.service.Selection() | |
vmap_sel_code = sel_serv.LookupType(lx.symbol.sSELTYP_VERTEXMAP) | |
vmap_trans_packet = lx.object.VMapPacketTranslation( | |
sel_serv.Allocate(lx.symbol.sSELTYP_VERTEXMAP)) | |
map_count = sel_serv.Count(vmap_sel_code) | |
for i in range(map_count): | |
packet_pointer = sel_serv.ByIndex(vmap_sel_code, i) | |
if vmap_trans_packet.Type(packet_pointer) == map_type: | |
map_name = vmap_trans_packet.Name(packet_pointer) | |
selected_vmap_names.append(map_name) | |
return selected_vmap_names | |
class MorphDuplicate(lxu.command.BasicCommand): | |
''' Command class for morph.duplicate ''' | |
def __init__(self): | |
lxu.command.BasicCommand.__init__(self) | |
def cmd_Interact(self): | |
pass | |
def cmd_Flags(self): | |
return lx.symbol.fCMD_MODEL | lx.symbol.fCMD_UNDO | |
def basic_Execute(self, msg, flags): | |
# check mesh selection | |
mesh_selection = ensure_mesh_selection() | |
if mesh_selection: | |
# get first selected mesh | |
mesh = mesh_selection[0] | |
# get selected morph names | |
selected_morph_names = get_selected_vmaps(lx.symbol.i_VMAP_MORPH) | |
for morph_name in selected_morph_names: | |
# Get the morph object. For now we have to avoid a direct name lookup | |
# via geometry.vmaps('MyMap'), due to a bug in the TD API. | |
morph = [m for m in mesh.geometry.vmaps.morphMaps if m.name == morph_name][0] | |
# create the new morph | |
new_morph_name = '%s_COPY' %morph.Name() | |
new_morph = mesh.geometry.vmaps.addMorphMap(new_morph_name, False) | |
# set the new morph's point positions based on the source morph's | |
for idx, position in enumerate(morph): | |
new_morph[idx] = position | |
# update geo | |
mesh.geometry.setMeshEdits() | |
return lx.result.OK | |
lx.bless(MorphDuplicate, "morph.duplicate") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment