PDA

View Full Version : need help on my MEL script


deebster
10-25-2006, 06:56 AM
hi. I'm new to MEL scripting and I need help with my script. Its a small script that creates reference planes for modelsheets. The problem I'm having is that I dont know how to apply the lambert shaders to the objects.

proc newMat(string $nmName){
eval("shadingNode -asShader lambert -name \"" + $nmName + "Mat\"");
eval("nurbsPlane -p 0 0 0 -ax 0 1 0 -w 8 -lr 1 -d 3 -u 1 -v 1 -ch 1 - name \"" + $nmName + "Ref\"");
};

string $refName[3] = {"front", "side", "back"};

int $i;
for ($i = size($refName); $i > 0; $i--) {
newMat($refName[$i-1]);
}

setAttr "frontRef.rotateX" 90;
setAttr "frontRef.translateZ" -25;
setAttr "sideRef.rotateZ" 90;
setAttr "sideRef.translateX" -25;
setAttr "backRef.rotateX" -90;
setAttr "backRef.translateZ" 25;

sparaig
10-26-2006, 01:52 AM
hi. I'm new to MEL scripting and I need help with my script. Its a small script that creates reference planes for modelsheets. The problem I'm having is that I dont know how to apply the lambert shaders to the objects.


Not surprising since it is relatively complicated.

Here's how to hook a texture file to a lambert shader and then hook THAT to a material. Derived from the MEL FAQ which I created my own cache of since it appears to be defunct.

Note you must first create a shading group and work with that. This code is lifted out of a set of procedures that takes a selection of MRI brain scans (450ish of them total) and makes each image into a lambert texture which is placed on a polygon plane that can be spaced properly and used as a reference image for drawing a brain.

global proc string createSliceTexture(string $imageName)
{
string $lambert = `shadingNode -asShader lambert`;
string $lambertSG = $lambert + "SG";
sets -renderable true -noSurfaceShader true -empty -name $lambertSG;
connectAttr -f ($lambert+".outColor") ($lambertSG+".surfaceShader");

// Make a file texture.
//
string $fileTex = `shadingNode -asTexture file`;

connectAttr -f ($fileTex+".outColor") ($lambert+".color");


setAttr -type "string" ($fileTex+".fileTextureName") $imageName;
setAttr ($lambert +".transparency") 0.5 0.5 0.5;

return $lambertSG;
};


//pick file from browser or whatever then...

$newPolyName = "whatever";

$lambertName = createSliceTexture( $newFileName);
polyPlane -n $newPolyName -w 25.6 -h 25.6 -sx 1 -sy 1 -ax 0 0 1 -tx 1 -ch 1;


sets -e -forceElement $lambertName;

Adam
10-26-2006, 03:44 AM
you can also simply use this command... the only downside is that it applies the shader based on what is selected. so you have to select the object you want the sahder to apply to before running the command.

select -r $newPolyName;
hyperShade -a $lambert;

hope this helps

deebster
10-26-2006, 09:04 AM
Hey guys. thanks for the help! :)

I actually played around with the script a little more after I posted. And I found this little script:

defaultNavigation -source lambertMat -destination |lambertRef|lambertRefShape.instObjGroups[0] -connectToExisting;

The script works so far...but please let me know if this is a no-no in the MEL scripting community.

I'll also try what you guys posted as well to experiment and get better at scripting. thanks again.

Mikademius
10-26-2006, 10:00 AM
I've scripted this earlier. Feel free to browse the code :) The script is located here:
http://www.final3.com/html/scripts/modellingsuite.htm

sparaig
10-26-2006, 04:38 PM
Hey guys. thanks for the help! :)

I actually played around with the script a little more after I posted. And I found this little script:

defaultNavigation -source lambertMat -destination |lambertRef|lambertRefShape.instObjGroups[0] -connectToExisting;

The script works so far...but please let me know if this is a no-no in the MEL scripting community.

I'll also try what you guys posted as well to experiment and get better at scripting. thanks again.


fantastic. I didn't know that that command existed. So basically, you get to use MEL to simulate using the UI. The script I gave bypasses the UI and who knows if it might leave a few important bits out. The defaultNavigation comand ensures (as far as I can tell from the documentation) that your new node is a 100% team player with the MayaUI-based stuff and you don't have to work with a selected node or object so it can be batched. Very nice. Thanks.


This helps me a lot, BTW. I found plenty of places where using the direct MEL commands didn't work properly because Maya's internal house-keeping of nodes didn't take place until AFTER my procedure had finished and a lot of connections didn't exist yet. This shouldn't happen using the defaultNavigation command if I read the documentation properly.

Again thanks.

CGTalk Moderation
10-26-2006, 04:38 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.