Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding
Announcements
We are currently migrating data within this board to improve the community. During this process, posting, replying, editing and other features are temporarily disabled. We sincerely apologize for any inconvenience caused and appreciate your understanding. Thank you for your patience and support.

Bug - nodeEditor's selectNode flag broken when using addNode in the same script

mikey.n
Enthusiast Enthusiast
1,267 Views
10 Replies
Message 1 of 11

Bug - nodeEditor's selectNode flag broken when using addNode in the same script

mikey.n
Enthusiast
Enthusiast

Hi,

 

When I use cmds.nodeEditor() in a script, it seems that any selectNode flags simply get ignored if they immediately follow an addNode command. It only seems to be ignored if the addNode flag results in an update to the node editor. (So running the script again sometimes works).

 

This is quite a bad bug, since many of the nodeEditor commands rely on using the selection in the window (such as the rootsFromSelection flag). If I cannot update the selection, then I cannot use these commands.

 

An example here, requires that the node editor is open. This script should make a sphere, add it to the node editor, deselect, and then reselect it.

sphere = cmds.polySphere()
cmds.select(cl=1)
cmds.nodeEditor('nodeEditorPanel1NodeEditorEd', rootNode='', e=1) #clear the editor
cmds.nodeEditor('nodeEditorPanel1NodeEditorEd', addNode=sphere, e=1) #add the sphere nodes to the graph
cmds.nodeEditor('nodeEditorPanel1NodeEditorEd', selectNode='', e=1) #clear the selection
cmds.nodeEditor('nodeEditorPanel1NodeEditorEd', selectNode=sphere, e=1)#select the sphere nodes

 

The result is that no nodes are selected after running. However if you re-run just the selectNode lines, the selection will be updated just fine.

 

Am I missing something here, or is this just straight up broken? I'm in Maya 2018.2 and this is a python script.

 

For some context, I'm trying to create a script to graph upstream/downstream connections to a single attribute of a node, instead of the whole thing. This relies heavily on the rootsFromSelection and selectNode flags, but without proper selection editing, I'm pretty much stuck. Is there any other way to achieve this?

 

 

Reply
Reply
0 Likes
1,268 Views
10 Replies
Replies (10)
Message 2 of 11

jmreinhart
Advisor
Advisor

I can't offer a solution but I got the same result when running that code, so it's not just you.

Reply
Reply
Message 3 of 11

mikey.n
Enthusiast
Enthusiast

Well, thanks for the gesture of solidarity at least! 😅

Reply
Reply
0 Likes
Message 4 of 11

mikey.n
Enthusiast
Enthusiast

Bumping again for a solution, or will I have to manually traverse the DG graph, adding nodes along the way?

Reply
Reply
0 Likes
Message 5 of 11

g2m.agent
Collaborator
Collaborator

no problem here.

Windows 10, Maya 2020.2

 

I think you should change “sphere” to “sp” or “mySphere” and try again.
sphere” is a built-in MEL command.

Reply
Reply
Message 6 of 11

jmreinhart
Advisor
Advisor

I ran the script with the sphere variables replaced with sphere0 in 2020.3 but I'm still getting the original result.

Reply
Reply
0 Likes
Message 7 of 11

mikey.n
Enthusiast
Enthusiast

@g2m.agent wrote:

no problem here.

Windows 10, Maya 2020.2

 

I think you should change “sphere” to “sp” or “mySphere” and try again.
sphere” is a built-in MEL command.


Are you running this script in python? I'd imagine so, since this won't work unedited in MEL. "sphere" is not a reserved keyword in the python interpreter, and as @jmreinhart  says, I'm still getting the broken result even after changing the variable name.

Just retested in 2020.2, windows 10, and the same broken result there as well. I can't move to 2020 anyway due to some needed plugins lacking 2020 support.

To be absolutely clear, the result I'm getting is a node editor window with three nodes in. All three nodes are unselected. 
This is incorrect. 
The result I should be getting is the same three nodes, but the polySphere and transform nodes should be selected.

Reply
Reply
0 Likes
Message 8 of 11

g2m.agent
Collaborator
Collaborator

 

see yourself.

Reply
Reply
0 Likes
Message 9 of 11

mikey.n
Enthusiast
Enthusiast

Thanks for the video, does it also work correctly for you if you run the example script all at once?

Either by selecting all the lines, or saving the script to the shelf?
If I run the script one line at a time then the bug doesn't appear.

Reply
Reply
0 Likes
Message 10 of 11

g2m.agent
Collaborator
Collaborator

I just looked at your question carefully. Running multiple select/cancel commands at the same time will indeed "lost" a selection or cancel. This problem has existed for many years.


My solution is to avoid using select commands. Instead, specify the variable name directly.

 

import maya.cmds as cmds
sphere = cmds.polySphere()
shapeNode = cmds.listRelatives(sphere,s=True)[0]
source = cmds.listConnections(shapeNode,t="polySphere")[0]

 

Reply
Reply
Message 11 of 11

mikey.n
Enthusiast
Enthusiast

Ahh, a bit disappointing to hear that. Are there any plans to get this bug fixed?
For now I'll look into traversing the DG graph manually, as you suggest, and adding all the nodes I find to the node graph as a second step. Thanks!

Reply
Reply