Learning Python Attributes


#1

Ive finally decided to get into scripting in maya but having some newby
difficulties with how to set attributes if someone could help me out.

after creating an area light i cant seem to define its attributes such as decay and intensity. Are they in an array or something or how do I access that data?

thanks

this obviously doesnt work putting the intensity it in a setAttr or as a shading node attribute

from maya import cmds as mc
mc.shadingNode ('areaLight', asLight=True,n='keyArea')

mc.move(0,21,0)
mc.rotate(-90,0,0)
mc.scale(10,10,10)
mc.setAttr(intensity='2')


#2

The way you have written it, the first 3 commands, move, rotate and scale, operate on the selected items, and this works because mc.shadingNode leaves the new light selected on creation.

But this is not good coding practice, since some commands, for example setAttr, need you to specify the object name, and sometimes the current selection is hard to manage inside a script. It is better to grab the result of one command and feed it into the others. I have changed your code to show how you can do this…

from maya import cmds as mc
areaLight = mc.shadingNode ('areaLight', asLight=True,n='keyArea')

mc.move(0,21,0, areaLight)
mc.rotate(-90,0,0, areaLight)
mc.scale(10,10,10, areaLight)
mc.setAttr(areaLight+'.intensity', 2)

David


#3

THanks alot!