Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import maya.cmds as cmds
- def get_inbetween_nodes(source_node, target_node):
- all_nodes = set()
- nodes = cmds.listConnections(source_node, source=False, destination=True)
- if nodes is None:
- return all_nodes
- for node in nodes:
- if node == target_node:
- continue
- all_nodes.add(node)
- all_nodes = all_nodes | get_inbetween_nodes(node, target_node)
- return all_nodes
- def graph_inbetween_nodes(source_node, target_node):
- inbetween_nodes = list(get_inbetween_nodes(source_node, target_node))
- nodes = [source_node, target_node] + inbetween_nodes
- cmds.select(nodes, replace=True)
- for node in nodes:
- cmds.nodeEditor("nodeEditorPanel1NodeEditorEd", edit=True, addNode=node)
- def graph_between_selection():
- sel = cmds.ls(sl=True)
- if len(sel) != 2:
- raise ValueError("You should have 2 nodes selected, not {}".format(len(sel)))
- try:
- graph_inbetween_nodes(sel[0], sel[1])
- except RuntimeError:
- try:
- graph_inbetween_nodes(sel[1], sel[0])
- except RuntimeError as e:
- if (
- str(e)
- == "maximum recursion depth exceeded while calling a Python object"
- ):
- cmds.warning("No nodes found between {} and {}".format(sel[0], sel[1]))
- if __name__ == "__main__":
- graph_between_selection()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement