How to create a node editor and display a list of nodes in it?

1,006 views
Skip to first unread message

Chad_Fox

unread,
May 5, 2017, 6:11:38 PM5/5/17
to Python Programming for Autodesk Maya
Hi all

I'm trying to write a script to display a node editor, populate it with a given list of nodes and frame them. Unfortunately when running in python, maya mostly only completes the first step of displaying the scriptedPanel node editor I'm making. Occasionally when running this code I do get a node editor with the nodes added, but not framed. 

Even though I have the name of said editor, the commands to add nodes and frame them do nothing when everything is run in one execution. If I run them separately and individually it works great!

I've tried using evalDeferred and utils.executeInMainThreadWithResult() to create the window first then run the nodeEditor commands, but no luck there. 

Any thoughts on how to approach this problem?

Thanks!

Enter code here...

nodes_to_display = cmds.ls(sl=True)


title = 'Custom Node Editor Window'
h = 700
w = 950
window_name = cmds.window(title, height=h, width=w)

form_layout = cmds.formLayout()
custom_node_editor = cmds.scriptedPanel(type="nodeEditorPanel", label="My Node Editor")
cmds.formLayout(form_layout, e=True, af=[(custom_node_editor, s, 0) for s in ("top", "bottom", "left", "right")])
cmds.showWindow(window_name)

editor_name = custom_node_editor + "NodeEditorEd"


print "Clear node editor"
cmds.nodeEditor(editor_name, e=True, rootNode='')  

print "adding nodes"
for node in nodes_to_display: 
    cmds.nodeEditor(editor_name, e=True, addNode=node)

print "layout nodes"
cmds.nodeEditor(editor_name, e=True, layout=True)

print "frame nodes"
cmds.nodeEditor(editor_name, e=True, frameAll=True)




Justin Israel

unread,
May 6, 2017, 1:25:44 AM5/6/17
to python_in...@googlegroups.com
On Sat, May 6, 2017 at 10:11 AM Chad_Fox <chadl...@gmail.com> wrote:
Hi all

I'm trying to write a script to display a node editor, populate it with a given list of nodes and frame them. Unfortunately when running in python, maya mostly only completes the first step of displaying the scriptedPanel node editor I'm making. Occasionally when running this code I do get a node editor with the nodes added, but not framed. 

Even though I have the name of said editor, the commands to add nodes and frame them do nothing when everything is run in one execution. If I run them separately and individually it works great!

I've tried using evalDeferred and utils.executeInMainThreadWithResult() to create the window first then run the nodeEditor commands, but no luck there. 

Any thoughts on how to approach this problem?

It seems to work for me if I either put a cmds.refresh() between the showWindow() and the layout/frame of the nodes, or you can use 

    cmds.evalDeferred(functools.partial(setupNodeEditor, editor_name))

and put the layout/frame into a setupNodeEditor(name) function.
 

Thanks!

Enter code here...

nodes_to_display = cmds.ls(sl=True)


title = 'Custom Node Editor Window'
h = 700
w = 950
window_name = cmds.window(title, height=h, width=w)

form_layout = cmds.formLayout()
custom_node_editor = cmds.scriptedPanel(type="nodeEditorPanel", label="My Node Editor")
cmds.formLayout(form_layout, e=True, af=[(custom_node_editor, s, 0) for s in ("top", "bottom", "left", "right")])
cmds.showWindow(window_name)

editor_name = custom_node_editor + "NodeEditorEd"


print "Clear node editor"
cmds.nodeEditor(editor_name, e=True, rootNode='')  

print "adding nodes"
for node in nodes_to_display: 
    cmds.nodeEditor(editor_name, e=True, addNode=node)

print "layout nodes"
cmds.nodeEditor(editor_name, e=True, layout=True)

print "frame nodes"
cmds.nodeEditor(editor_name, e=True, frameAll=True)




--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/5af628e9-65f8-44ff-9c38-e1bbfeb4176d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chad Fox

unread,
May 9, 2017, 6:21:20 PM5/9/17
to Python Programming for Autodesk Maya
Hey Justin

Thanks for the suggestion. Looks like this works without a hitch when run in Maya, but I'm sad to say that as soon as I put it in a module and called it to display some nodes I was checking, it did not work at all. it just opened the custom node editor and displayed the last thing I had in my normal node editor.  

Is it possible to do something like this with open maya? I would assume so, I'm seeing no reference to creating maya windows like the node editor in the API documentation. 

Thoughts?


-Chad


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1jKsiwKEZbDE3LYeraqdP7MiFUcc0e465AHgGoSPXqTQ%40mail.gmail.com.

Justin Israel

unread,
May 9, 2017, 6:37:23 PM5/9/17
to python_in...@googlegroups.com
On Wed, May 10, 2017 at 10:21 AM Chad Fox <chadl...@gmail.com> wrote:
Hey Justin

Thanks for the suggestion. Looks like this works without a hitch when run in Maya, but I'm sad to say that as soon as I put it in a module and called it to display some nodes I was checking, it did not work at all. it just opened the custom node editor and displayed the last thing I had in my normal node editor.  

Is it possible to do something like this with open maya? I would assume so, I'm seeing no reference to creating maya windows like the node editor in the API documentation. 

Thoughts?

Not sure. Seems like it wouldn't be necessary to have this as a first class Maya API concept if you can create one through MEL or Python. 

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAJ4oLs5020oddtb-w0dbSPFnbx9hX6qQo-mQ2tSccr748JcOAg%40mail.gmail.com.

Chad Fox

unread,
May 9, 2017, 6:50:14 PM5/9/17
to Python Programming for Autodesk Maya
Seems like it, but without a solution to create the editor and control it in a single run I'm at a loss :)


-Chad


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0SiVjahngAjEg2tQRYNM4yQ4kh8qKiR3RCxm60Lrzb5Q%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages