Skip to content

Instantly share code, notes, and snippets.

@zewt
Created April 3, 2018 04:02
Show Gist options
  • Save zewt/4f5e54d20839697c94df0afbf67e41a9 to your computer and use it in GitHub Desktop.
Save zewt/4f5e54d20839697c94df0afbf67e41a9 to your computer and use it in GitHub Desktop.

Revisions

  1. zewt created this gist Apr 3, 2018.
    32 changes: 32 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    import sys
    import pymel.core as pm

    def pick_walk(direction, add=False):
    nodes = pm.ls(sl=True)
    new_nodes = []
    non_dag_nodes = []
    for node in nodes:
    # Make a list of non-DAG nodes.
    if not isinstance(node, pm.nodetypes.DagNode):
    non_dag_nodes.append(node)
    continue

    pm.select(node, ne=True)
    pm.pickWalk(direction=direction)
    new_nodes.extend(pm.ls(sl=True))

    pm.select(d=True)

    # If any non-DAG objects were selected, like components, use the regular pick walk command to handle them.
    if non_dag_nodes:
    pm.select(non_dag_nodes)
    pm.pickWalk(direction=direction)

    # Add our individual pick walking results.
    pm.select(new_nodes) #, ne=True, add=True)

    # If add is true, reselect the original selection.
    if add:
    pm.select(nodes, ne=True, add=True)

    pick_walk('down', False)