I’m fairly new to coding but I’m trying to write a mel script that will copy attributes from one shader to a different type of shader.
This is what I’ve got so far:
//Script selects color value and reflection roughness value from first selected (vray) shader object and applys it to second (redshift) shader object
//select materials from objects
hyperShade -smn;
//put selections into an array
string $selection[] = `ls -selection`;
//create a variable that has the value of the first shader .color slot
vector $attrcolor = `getAttr ($selection[0] + ".color")`;
//create a variable that has the value of the first shader .reflectionGlossiness slot
float $attrroughness = `getAttr ($selection[0] + ".reflectionGlossiness")`;
//apply the value of the first shaders .color attribute to the second shaders .diffuse_color attribute
setAttr ($selection[1] + ".diffuse_color") ($attrcolor.x) ($attrcolor.y) ($attrcolor.z);
//apply the value of the first shaders .reflectionGlossiness attribute to the second shaders .refl_roughness attribute
setAttr (($selection[1] + ".refl_roughness"), $attrroughness);
Ok. So this works to take a color (which is an array value for R, G, and B values) and copy it to the second shader. It also works with numerical values (float values like reflection roughness) and applies those to the second shader. What if there were an image attached to the diffuse color slot though rather than a color? What kind of code would copy that over? I think it can somehow be done with a connectioninfo command but I can’t figure it out.
Any help would be greatly appreciated!