Selecting Nodes with Python

Selecting Nodes with Python

danispag
Enthusiast Enthusiast
5,672 Views
3 Replies
Message 1 of 4

Selecting Nodes with Python

danispag
Enthusiast
Enthusiast

Hi, I would like to select nodes with python. I managed to make a list and print the object that i want however when i'm running the select function nothing is selected.

 

Please refer to image attached below.

 

Your help is very much appreciated.

Thanks and regards

Daniel

0 Likes
Accepted solutions (1)
5,673 Views
3 Replies
Replies (3)
Message 2 of 4

lanh.hong
Alumni
Alumni
Accepted solution

Hi Daniel,

 

When you use the select command, you can add each node to the active selection list by using the add flag. As you loop through all of the nodes, this will select all of it.

 

import maya.cmds as cmds
nodes = cmds.ls(type = ['transform']) nodesLen = len(nodes) for i in range(0, nodesLen): print(nodes[i]) cmds.select(nodes[i], add=True)

More details about the select command and its flags can be found here: http://help.autodesk.com/view/MAYAUL/2018/ENU/?guid=__CommandsPython_select_html .

 

Hope this helps!

 

Thanks,

Lanh


Lanh Hong
Developer Technical Services
Autodesk Developer Network



Message 3 of 4

Anonymous
Not applicable

If the only thing that you want to do is selecting the nodes listed by the cmds.ls function, you don't need to loop over the list of nodes, the cmds.select() function accepts a list as parameter:

 

import maya.cmds as cmds

nodes = cmds.ls(typ=['blendColors', 'clamp'])
cmds.select(nodes)
Message 4 of 4

danispag
Enthusiast
Enthusiast

Thanks a lot, the 'add' flag was the solution 🙂

0 Likes