Read color file and apply to Transparency

Read color file and apply to Transparency

kamerosoul1
Explorer Explorer
459 Views
4 Replies
Message 1 of 5

Read color file and apply to Transparency

kamerosoul1
Explorer
Explorer

Hi:

I am new in MEL programming.

I need a MEL script to connect a selected object color attribute and apply to the same object to transparency attribute.

It may have this format or other if proposed:

connectAttr -f file1_png.outTransparency file1obj.transparency;

where file1_png is the selected color file and file1obj is the selected object file

I tried to read selected data as next:

 

//Select an object first
string $mySel[] = `ls -sl`;
if (size($mySel) == 0) {
$msgbox = `confirmDialog -title "Error"
-message "Please select the objects that need apply transparency!"
-button "Ok"`;
}
string $shapes[] = ls("-sl", "-o", "-dag", "-s");
string $myMaterial[] = `listConnections -type "shadingEngine" $shapes`;

for ($items in $myMaterial)
{
string $surfaceShader[0] = `listConnections ($items + ".surfaceShader")`;
print ($surfaceShader[0]);
string $A = ($surfaceShader[0]);
}

 

But I do not know where and how apply connectAttr command

I hope anyone can help me

Thanks

Accepted solutions (1)
460 Views
4 Replies
Replies (4)
Message 2 of 5

howard.cohl
Participant
Participant

Hi there. I'm not sure if this helps, but I am doing something similar. For instance for a green surface, so do the following commands and they seem to work:

 

file -import -type "OBJ" -ns "den1" "/Users/hcohl/maya/myOBJfiles/den1.obj";/

select -r den1:Mesh;
polyAverageVertex -i 10 -ch 1 den1:Mesh;
polyAverageVertex -i 10 -ch 1 den1:Mesh;
polyAverageVertex -i 10 -ch 1 den1:Mesh;
polyAverageVertex -i 10 -ch 1 den1:Mesh;
polyAverageVertex -i 10 -ch 1 den1:Mesh;
polyAverageVertex -i 10 -ch 1 den1:Mesh;
polyAverageVertex -i 10 -ch 1 den1:Mesh;
polyAverageVertex -i 10 -ch 1 den1:Mesh;
polyCloseBorder -ch 1 den1:Mesh;
polySoftEdge  -a 30 -ch 1 den1:Mesh;


// Innermost Green surface
select -cl;
select -r den1:Mesh;
shadingNode -asShader blinn -name "surface1";
sets -renderable true -noSurfaceShader true -empty -name "surface1SG";
connectAttr -f "surface1.outColor" "surface1SG.surfaceShader";
sets -edit -forceElement "surface1SG" |den1:Mesh;
setAttr "surface1.color" -type double3 0.392 1.608 0.392;
setAttr "surface1.ambientColor" -type double3 0.133 0.133 0.133;
setAttr "surface1.transparency" -type double3 0.604 0.604 0.604;
0 Likes
Message 3 of 5

kamerosoul1
Explorer
Explorer

Thank you sir for sharing your code. I will try to use it to fix my problem

0 Likes
Message 4 of 5

mcw0
Advisor
Advisor
Accepted solution

You're almost there.  Everything looks right.  After you get your surfaceShader, you can use listConnections to get the image file connected to the color channel.  Then use connectAttr to connect that result to your transparency.

0 Likes
Message 5 of 5

kamerosoul1
Explorer
Explorer

Thank you very much  @mcw0

Now it is fixed

The missing part was next:

string $SSB[0] = `listConnections ($A + ".color")`;

string $B = ($SSB[0]);

connectAttr -f ($B + ".outTransparency") ($A + ".transparency");

0 Likes