Maya python Error - object is not iterable

Viewed 122

I am new to python and I am trying to do a simple script to find all the floatConstant nodes in the Hypershade named "rangeImput#" and update all the values at once.

However, it returns this error: 'NoneType' object is not iterable #

The funny thing is; if I create the script to change what is selected manually it works, but selecting the node by its name doesn't. Any help is much appreciated.

from maya import cmds

selection = cmds.select("*rangeImput*", allDagObjects=False, noExpand=True)

newRange= 30

for x in selection:

    cmds.setAttr (x +".inFloat", newRange)
1 Answers

select just marks the objects as selected and returns None (Maya docs). Try this:

from maya import cmds

# mark objects as selected
cmds.select("*rangeImput*", allDagObjects=False, noExpand=True)

# get selected objects
selected_objects = cmds.ls( selection = True )

newRange = 30

for x in selected_objects:
    cmds.setAttr (x +".inFloat", newRange)

Related