PDA

View Full Version : assigning material through mel


h0tice
02-18-2004, 10:12 AM
hi there,

i how can i assign a material through mel? or is it possible to do this, i look to the script editor everytime i assign a material in an object but it do not echo the command.

i could not find any command also in the maya docs.

thanx.

h0tice
02-18-2004, 11:07 AM
ok i got here my script, but everytime i execute it i only find the shader but it did not assign the shader to my selected object.

what is my error here?

string $sel[] = `ls -sl`;

for ($i = 0; $i < size($sel); $i++)
{
setAttr ( $sel[$i] + ".motionBlur" ) 0;
setAttr ( $sel[$i] + ".visibleInReflections" ) 0;
setAttr ( $sel[$i] + ".visibleInRefractions" ) 0;
}

string $bgName = "bgShader";
string $bgMat = `shadingNode -asShader useBackground`;
sets -renderable true -noSurfaceShader true -empty -name ( $bgMat + "SG" );
connectAttr -f ( $bgMat + ".outColor" ) ( $bgMat + "SG.surfaceShader" );
sets -e -forceElement ($bgMat + "SG");

and here is the error that maya send me:

// Warning: Cannot add the following items to the set since the set has restrictions on membership: useBackground1 //
// Warning: None of the items can be added to the set //



thanx

Marcel
02-19-2004, 08:20 AM
Here is a procedure that I used to assign a material to the scene selection. It's not very fast because it selects every object to apply the material. Especially when you have a lot of faces selected (in component mode) it's really slow. If somebody knows a faster way I'd like to hear! :)



/////////////////////////////////////////////////////
// mvAssignMaterial (string $materialName)
// assigns $materialName to current scene selection

global proc mvAssignMaterial( string $materialName )
{

// current selection
string $objectName[] = `ls -sl -fl`;
int $numberOfObjects = size($objectName);

if($numberOfObjects != 0 )
{
for($i=0; $i<$numberOfObjects; $i++)
{
// select object
select -r $objectName[$i];
// assign material
hyperShade -assign $materialName;
}
} else print "No object selected";
// return to old selection
select -r $objectName;

}

h0tice
02-19-2004, 09:37 AM
thanx for the idea marcel now here is my code and it works fine for every selected objects:

string $sel[] = `ls -sl`;
string $bgName = "bgShader";
string $bgMat = `shadingNode -asShader useBackground`;
sets -renderable true -noSurfaceShader true -empty -name ( $bgMat + "SG" );


global proc assignMat( string $bgMat )
{
hyperShade -assign $bgMat;
}

select $sel;


assignMat ($bgMat)


thanx a lot.

h0tice
02-20-2004, 11:41 AM
hi again here is my final script:

//created by oliver magno
//date created: 021904
//description: this script will create a useBackground shader
// and automatically assign to selected objects,
// it will also set all the selected objects'
// motionBlur to zero.


string $sel[] = `ls -sl`;
for ($i = 0; $i < size($sel); $i++)
{

setAttr ($sel[$i] + ".motionBlur") 0;
setAttr ($sel[$i] + ".smoothShading") 0;
setAttr ($sel[$i] + ".visibleInReflections") 0;
setAttr ($sel[$i] + ".visibleInRefractions") 0;


}

string $bgName = "bgShader";
string $bgMat = `shadingNode -asShader useBackground`;
setAttr ($bgMat + ".reflectivity") 0;
setAttr ($bgMat + ".reflectionLimit") 0;
setAttr ($bgMat + ".specularColor") -type double3 0 0 0 ;
sets -renderable true -noSurfaceShader true -empty -name ( $bgMat + "SG" );


global proc assignMat( string $bgMat )
{
hyperShade -assign $bgMat;
}

select $sel;
assignMat ($bgMat)


thanx again Marcel and to all.
:)

CGTalk Moderation
01-17-2006, 12:00 PM
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.