Skip to content

Instantly share code, notes, and snippets.

@rondreas
Created November 19, 2018 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rondreas/e39f025641a0994f81ad4feb175abf3d to your computer and use it in GitHub Desktop.
Save rondreas/e39f025641a0994f81ad4feb175abf3d to your computer and use it in GitHub Desktop.
Quick script to allow hotkeying a toggle for converting selection, to imitate the default command of CTRL + F9/F10/F11.
"""
Quick script to allow hotkeying a toggle for converting selection, to imitate the default
command of CTRL + F9/F10/F11.
"""
import pymel.core as pm
class eSelection(object):
""" Enum for selection convertion. """
object = 0
face = 1
edge = 2
vert = 3
def getActive():
""" Check current selection to find if we're currently only selecting a specific component. """
if all(isinstance(x, pm.MeshFace) for x in pm.selected()):
return eSelection.face
if all(isinstance(x, pm.MeshEdge) for x in pm.selected()):
return eSelection.edge
if all(isinstance(x, pm.MeshVertex) for x in pm.selected()):
return eSelection.vert
# If no matching component, default to object
return eSelection.object
def selectionToggleForward():
""" Convert selection forwards, ...(face) -> object -> vert -> edge -> face -> (object)... """
active = getActive()
if active is eSelection.object:
pm.mel.ConvertSelectionToVertices()
if active is eSelection.vert:
pm.mel.ConvertSelectionToEdges()
if active is eSelection.edge:
pm.mel.ConvertSelectionToFaces()
if active is eSelection.face:
# If face, convert selection to objects (transforms)
pm.select( [shape.getTransform() for shape in pm.ls(pm.polyListComponentConversion( fromFace = True ))], replace = True )
def selectionToggleBackward():
""" Convert selection backwards, ...(face) <- object <- vert <- edge <- face <- (object)... """
active = getActive()
if active is eSelection.object:
pm.mel.ConvertSelectionToFaces()
if active is eSelection.vert:
# If vertex, convert selection to objects (transforms)
pm.select( [shape.getTransform() for shape in pm.ls(pm.polyListComponentConversion( fromVertex = True ))], replace = True )
if active is eSelection.edge:
pm.mel.ConvertSelectionToVertices()
if active is eSelection.face:
pm.mel.ConvertSelectionToEdges()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment