PDA

View Full Version : assign a material to a polygon with MEL


daviddoria
04-19-2008, 03:21 PM
I want to assign a material that I've already setup (transparency, color, etc) to a new object that I create with mel

ie.

polyPlane -name myplane
assign MyBlinn to myplane

how would I do that?

Thanks!

Dave

wajdyf
04-19-2008, 03:37 PM
polyPlane -name myplane;
string $myBlinn = `shadingNode -asShader blinn`;
select myplane;
hyperShade -assign $myBlinn;


or if u created the shader beforehand :

polyPlane -name myplane;
select myplane;
hyperShade -assign THENAMEOFYOURSHADER;

daviddoria
04-19-2008, 03:48 PM
awesome, thanks - is there a way to do it without using "select"? i mean assign the material directly to an object by name?

Maybe this is not a problem, but I will be calling this from a c++ plugin and I dont know if "select" takes some time or will mess anything up?

Thanks,

Dave

wajdyf
04-19-2008, 03:53 PM
polyPlane -name myplane;
hyperShade -assign THENAMEOFYOURSHADER;

WORKS just fine. Since maya automatically selects the newly created entity

geoff3dnz
04-22-2008, 12:18 AM
or assign the object to the shading group set:

polyPlane -n "myPlane";

sets -forceElement "myBlinnSG" "myPlane";

//you'll have to check the name of the
//shading group or rename it beforehand.

sj_bee
04-23-2008, 11:02 AM
//you'll have to check the name of the
//shading group or rename it beforehand.
like this...
//if $shader is the name of your shader
//and $object is the name of your object

string $shadingGrp[] = `listConnections -type shadingEngine $shader`;

sets -forceElement $shadingGrp[0] $object;

CGTalk Moderation
04-23-2008, 11:02 AM
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.