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

mikey.n
Enthusiast

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?

 

 

0 Likes
Reply
1,210 Views
10 Replies
Replies (10)

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.

mikey.n
Enthusiast
Enthusiast

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

0 Likes

mikey.n
Enthusiast
Enthusiast

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

0 Likes

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.

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.

0 Likes

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.

0 Likes

g2m.agent
Collaborator
Collaborator

 

see yourself.

0 Likes

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.

0 Likes

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]

 

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!