One task I find myself doing often is working with skinned polygon meshes. I personally find it easier to select mesh components using the Artisan Selection brush; It’s a fantastic tool!
This works great until I want to exit the brush tool back into the normal marquee selection tool to add bones or other transform nodes into the current component selection. Upon exiting the Artisan tool, the selection masks are still set in a way which prevents you from selecting mixed objects and components simultaneously.
I have been working around this by storing my artisan selection in a Selection Set, exiting the tool, reselecting the set, then shift selecting my transforms. After I’m done, I then have to delete my temporary set. This workflow got annoying enough for me to write a little script to retain the current component selection, toggle back into marquee selection mode, and reset the appropriate masks.
I wanted to share this with others, who might have also been plagued with similar findings. Perhaps there’s another way to circumvent the problem… this was my solution:
import pymel.core as pmc
def getSelectionMask():
'''
Retrieves the current polygon selection mask and returns
the string used to pass into selectType maya command
'''
if pmc.selectMode( q=True, component=True ):
if pmc.selectType( q=True, meshComponents=True ):
return 'meshComponents'
elif pmc.selectType( q=True, facet=True ):
return 'facet'
elif pmc.selectType( q=True, edge=True ):
return 'edge'
elif pmc.selectType( q=True, vertex=True ):
return 'vertex'
elif pmc.selectType( q=True, puv=True ):
return 'puv'
elif pmc.selectType( q=True, pvf=True ):
return 'pvf'
else:
raise Exception('getSelectionMask: Undefined return value')
else:
return 'allObjects'
def exitAndRetain():
'''
Returns the user to the default selection tool while retaining the active
component selections.
The artistan selection tool doesn't allow you to select both components
and objects together.
'''
sel = pmc.ls( sl=True,fl=True )
hi = pmc.ls( hl=True )
mask = { 'ocm':True, getSelectionMask():True }
# Return to the default selection tool
if pmc.currentCtx() == 'artSelectContext':
pmc.setToolTo( 'selectSuperContext' )
# Return to typical component selection mode
pmc.selectMode( o=True ) # Goto object mode (green)
pmc.hilite( hi, r=True ) # with our mesh highlited (now blue)
pmc.selectType( **mask ) # using the desired component selection mask (verts/edges/faces/etc)
pmc.select( sel, r=True ) # we then reselect the stored components.
At this time, I have exitAndRetain() bound to a hotkey. There’s likely a scriptJob workflow which could handle the trigger for you if someone wanted this to happen automatically, and felt like pursuing.
-csa