Simple? Changing shading group via MEL


Hi there

I want to write a MEL script that automates the task of changing the shading group of objects in a few secene files of mine to faclilitate rendering passes for compositions.

So I sat down and figured out how to switch shading group via MEL - a done deal I thought… but no. It got snagged on what I believe are instanced objects. I did a for loop like this:

for ($i = 0; $i < size($nodes) ;$i++)
{ sets -edit -forceElement $shadingGroup $nodes[$i]; }

…but this only seems to work for non-instanced geometry :frowning: I have a hall with pillars that are instanced, and for all of them (but the original) the change does not seem to “stick” - they stay with the original shading group.

I am a bit tired right now so I wondered if any of you had any ideas that could save me some headaches ?

/ Daniel



Check to verify you are getting the instance transform nodes when you fill nodes, and not just the shape node.


Ah - found the problem.

Thanks sbp for your help. Unfortunately the problem was not the sets command but rather the command I used to get the (transform)nodes: listConnections - which did not work as I expected. I haven’t figured out a solution yet though, but I’ll get there eventually :slight_smile:

/ Daniel


Found it! :slight_smile:

For curious people:
I used listConnections to get all the connections to a display layer. The problem with this approach was apparently that the layer was connected to the shape node and not the transform node… so when I used listConnections, I only got the first parent transform and not the rest.

Took a while to figure that one out. Works like a charm now - I used listRelatives -allParents on the shape nodes to retrieve all transforms.

/ Daniel


This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.