Hi there,
heres a thing I cant understand in Maya pymel;
Im using this very basic cmd to assign a shader to shapes in a loop:
pm.sets( myShader ,edit=1, forceElement=myObj)
but it returns:
Warning: None of the items can be added to the set
while if I use the same cmd on the Transforms it will work…
which is weird - since to be able to get a shadingGroup from a mesh, you need to select the shape and not the Transform…
shader = pm.listConnections(myShape ,type = ‘shadingEngine’) – of course theres a connection between shape and sg but its the overall philosophy that puzzles me.
Does anybody knows about this issue and can explain it, plz?
Sets command
The sets
command’s forceElement parameter should be the actual set and the first argument should be the objects that get added to the set.
So something like this:
pm.sets( objects,edit=1, forceElement=shading_engine)
Also see:
http://help.autodesk.com/cloudhelp/2015/ENU/Maya-Tech-Docs/CommandsPython/index.html
Maybe that’s where something goes wrong?
Maybe listSets over listConnections?
listSets
Besides that (and not many people seem to know this) getting the shadingEngine from a mesh can be done with the listSets command.
I’ve done some tests and listSets definitely beats listConnections on performance tests; though I’ve seen it behave inconsistently when working with namespaces.
Just so you know you can also have a look at that command, but do keep in mind that it might behave differently.
listConnections
Note that a connection might (theoretically) exist between a shape and a shadingEngine for other reasons than it being assigned the shader. Most of the time it will be fine though, like 99.99%.