View Full Version : MEL to find textured vertex clusters

04 April 2006, 09:39 PM
Well I can simply right click on a material and say "Select Objects with Material" and it will show this kind of stuff...
select -cl; select -r someobj_body.f[120] someobj_body.f[125:212] ... etc.
but to write a MEL script to do that is extremely difficult so I have come here to see if anyone knows offhand what to do (or can help figure it out).
Basically I want to replace all shaders in a complex rig with a maskShader (Matte Opacity 0.0 and Color black, etc.)
If I do that with a complex rig (group/trunk) all sorts of things barf on it, so I wrote a quick script to set it to all items and let those that barf barf and those that won't don't.

string $storeSel[] = `ls -sl`;
string $selection[] = `ls -g -dag -ap -sl`;
string $obj;

print "Started setting Mask Shader to";
print $storeSel;
print "/n";
print "Items found ";
print $selection;
print "/n";

for($obj in $selection) {
print ("Item: " + $obj + "/n");
select $obj;
hyperShade -assign maskShader;
select $storeSel;

This works fine until it runs into mesh with different textures assigned to different vertex clusters.
I believe they are hidden in instObjGroups (iog) of which there is not much said about here (or anywhere except what is it? reply: I don't know).
So my search has taken me to and through various commands...
listSets seems like a good place to start listing all sets shows things like skinCluster1Set exist but if you select it...

listSets -as;
// Result: initialShadingGroup ... lots of stuff... skinCluster1Set ... more stuff //

select skinCluster1Set;
// Error: No object matches name: skinCluster1Set //

sets -q skinCluster1Set;
// Error: No object matches name: skinCluster1Set //

It's not found for sets, object select, etc. which is strange to me since itís found by listSets.

Basically I want all the vertex groups of a mesh selected so the maskShader can be assigned.

I know with the GUI it would only take a minute but scripts save time and have no human error, and automated pipelining becomes more plausible etc.

Maybe Render Layers can help set one layer to be a mask object for another layer or something completely different I am currently unaware of, whatís your approach?

I will continue searching in the mean time.
I think this is a good one for those that like a challenge.

04 April 2006, 11:44 AM
Here is my progress on this problem ...

ls -geometry

leds to a "*Shape" name not normally visible in the outliner or hidden with a "*Deformed"

listConnections -source true -type shadingEngine somegeosShape

leds to a collection odd groupID##s mixed with shaderNameSGs the "*SG"s when selected are ultimately the collection of faces you can use to re-assign a (mask) shader to.
Preferably one should be able to remember the old shader and be able to restore it later via render pass MEL scripts, or have mask duplicates in the other render passes/layers.

Anyway I believe I can proceed at this time with this information.

I am still interested in '*.iog' which I think is where it's at, but this will do for this problem.

04 April 2006, 08:22 PM
dude I havent really read your hole post because I have no time right now, but I think this will help you. The command to select all the objects that are assigned to a material is:

hyperShade -objects NAME_OF_THE_MATERIAL;

This will select all the objects that have that specific material assigned to them...

hope it helped


05 May 2006, 03:51 AM
Thanks that does help but it does not explain what shaders are part of some meshes multiple face cluster texture assignments.

I have also discovered that if you list the ShaderGroup (SG) you get the face list that the "Select object with material" GUI command or hyperShade -objects @texture (thanks) shows.

ls -sl
// Result: someshape_body.f[0:22] someshape_body.f[59:209] etc

then if you select them you get something else showing in the attributes panel like a blend or tweak etc. (I suppose not totally the correct entity for the cluster possibly hidden in the IOG array).

select someshape_body.f[0:22] someshape_body.f[59:209] etc

That could be stored for replacing the original texture back again later.

Ultimately I still ponder the IOG and how to extract the data directly, but when it comes to Masking...

One normally in XSI etc. can do this in Render passes/layers so I explored that further.

It seems when one does a shader override a new option appears to "Assign Material override to "saidShader", this does exactly (I think) what my code does and gets past all the warnings and errors and actually assigns the mask shader.

I suppose next I have to look into render layer commands and see what programmatic ways exist to automate it there.

Any hints about setting hyperShade overrides for certain layers in MEL?

05 May 2006, 02:02 PM
Dude. You problem is becoming very challenging. I like that. :) But there is just one thing I don't understand, and lets see if I get this clear. You have a mesh with a bunch of vertices "added" into a cluster right? or a skinCluster....And then you want to add the maskShader to those vertices right?

If I am correct, perhaps it would be better to select those vertices, "convert" the selection to faces, and then assign the shader. I think it would be more simple. But I don't know if I am understanding the problem. Correct me if I am wrong...


CGTalk Moderation
05 May 2006, 02:02 PM
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.