SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import maya.cmds as cmds
  2.  
  3.  
  4. def get_inbetween_nodes(source_node, target_node):
  5.     all_nodes = set()
  6.     nodes = cmds.listConnections(source_node, source=False, destination=True)
  7.  
  8.     if nodes is None:
  9.         return all_nodes
  10.  
  11.     for node in nodes:
  12.         if node == target_node:
  13.             continue
  14.         all_nodes.add(node)
  15.         all_nodes = all_nodes | get_inbetween_nodes(node, target_node)
  16.  
  17.     return all_nodes
  18.  
  19.  
  20. def graph_inbetween_nodes(source_node, target_node):
  21.     inbetween_nodes = list(get_inbetween_nodes(source_node, target_node))
  22.     nodes = [source_node, target_node] + inbetween_nodes
  23.     cmds.select(nodes, replace=True)
  24.  
  25.     for node in nodes:
  26.         cmds.nodeEditor("nodeEditorPanel1NodeEditorEd", edit=True, addNode=node)
  27.  
  28.  
  29. def graph_between_selection():
  30.     sel = cmds.ls(sl=True)
  31.     if len(sel) != 2:
  32.         raise ValueError("You should have 2 nodes selected, not {}".format(len(sel)))
  33.     try:
  34.         graph_inbetween_nodes(sel[0], sel[1])
  35.     except RuntimeError:
  36.         try:
  37.             graph_inbetween_nodes(sel[1], sel[0])
  38.         except RuntimeError as e:
  39.             if (
  40.                 str(e)
  41.                 == "maximum recursion depth exceeded while calling a Python object"
  42.             ):
  43.                 cmds.warning("No nodes found between {} and {}".format(sel[0], sel[1]))
  44.  
  45.  
  46. if __name__ == "__main__":
  47.     graph_between_selection()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top