Mel script....selection set to material assignment...

Mel script....selection set to material assignment...

Anonymous
Not applicable
3,172 Views
2 Replies
Message 1 of 3

Mel script....selection set to material assignment...

Anonymous
Not applicable

I need a mel script that will look at a meshes various face selection sets and use these set names to assign unique materials with that name to each set of face. Lets just say lambert for now but I eventually need it to apply VrayMtls but I think I can figure that part out. I have a mesh that comes into maya with a unique face selection set for each material. I just want to loop through those sets, taking their names, and apply a material to each set with that same name. This should be pretty simple but I cannot figure it out. 

 

I think it should involve the listSets command and a for-loop but I cannot seem to be able to make an array of the sets to loop through. Mel freaks out every time I try to declare listSets as a variable. 

 

How would I do this?

0 Likes
3,173 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Ok, so I was able to make a string work:

 

string $sets[]=`listSets -as`;

 

This will deliver EVERY set in my scene. But I only want to be dealing with the ones in the set editor...the ones that show up at the bottom of the outliner. They each have a unique name but have a common suffix...so if there was a way to wildcard them that would work to define a new list of just the sets I want....but I don't know how to do that...

0 Likes
Message 3 of 3

Anonymous
Not applicable

I thought on this some more and this is what I came up with:

 

```

string $sets[]=`listSets -as`;
for($s in $sets){
if(`objExists $s`){

if(`setFilterScript $s`){
if(!`gmatch $s "modelPanel*"`){

$newName=substituteAllString($s, "ncl1", "mtl");
$newMtl=`shadingNode -as -n ($newName +"_VRAY") VRayMtl`;
select $s;
hyperShade -assign $newMtl;

}
}
}
}

 

```

It seems to work pretty well in a fresh load of maya. It will scan the sets of an object that has a bunch of poly-face sets and apply a vray material to each set with the name of the set. The problem is that it doesn't seem to work unless you restart maya each time. I guess for now it does what I need it to do even if I have to restart maya each time although I'd love it to work better. If anyone with actual scripting experience has any input please let me know. 

 

I bring models from modo into maya all the time and have been trying to come up with a good way to reshade them. This comes close but could be better...

 

0 Likes