Friday, January 17, 2014

Applying similar shader to Instances

Had this same issue 3 years ago. Just found this script.

1. Go to master of instances and switch to select faces.
2. Select faces to apply shader.
3. Run script using "select -r (expandSelection());".
4. Apply shader.

apply-shaders-to-all-maya-instances

In-case the script ever goes down, backup here. This is from Janne Ojala. Thank you.

/* jooCCRequestedExpandSelectionToInstances.mel 0.1
Authors: Janne 'Joojaa' Ojala
Testing: if it works after a suitably long time without
much problems let me know. Report any problems.
License: Creative Commons, Attribution, Share Alike
Request by: Toast
About:
A simple script that rxpand selection to each instance if only
one instace is selected
Usage:
select any number of faces on one object and run:
select -r (expandSelection())
or
sets -e -forceElement blinn1SG (expandSelectionToInstances());
to assign directly to shaders
Changelist:
06.03.2012 - Original file
*****************************************************************/
global proc string[] expandSelection() {
string $selection[] = `ls -sl`;
string $hl[] = `ls -hl`;
string $ret[];
$hl = `listRelatives -shapes $hl`;
//if (size($hl) > 1)
// error("select only in one object");
$hl = listRelatives("-parent", "-f", `ls -ap $hl`);
for ($item in $selection){
$match = `match "\.[^.]*$" $item`;
for ($item in $hl){
$ret[size($ret)]=($item+$match);
}
print "//Result: Sucessfully applied selection to all instances \n";
}
return $ret;
}