connect texture to some selected lights by python

connect texture to some selected lights by python

Anonymous
Not applicable
452 Views
2 Replies
Message 1 of 3

connect texture to some selected lights by python

Anonymous
Not applicable

Hi,

I have created some aiAreaLights and noisetexture("noise1").

I wanted to connect "noise1.outColor" to all "aiAreaLightShape.color" which I selected.

So I selected some lights and executed below one. 

 

for root_obj in pm.selected():
     target_list = root_obj.listRelatives(allDescendents=True)
     target_list.append(root_obj)
     for obj in target_list:
           cmds.connectAttr("noise1.outColor","{}.color".format(obj))

 

But I could connect to only one light which I selected at first.

And also there was error.

 

# Error: RuntimeError: file <maya console> line 5: Maya command error #

 

Could anyone tell me how can I fix it to connect to all lights?

0 Likes
453 Views
2 Replies
Replies (2)
Message 2 of 3

Raul_Teleki
Explorer
Explorer

Have you tried forcing the connection?
cmds.connectAttr("noise1.outColor","{}.color".format(obj), f=True)

Also i would not mix pymel and cmds.

 

0 Likes
Message 3 of 3

Raul_Teleki
Explorer
Explorer

You could also do a try and except to make the loop continue if something fails.

0 Likes