Hey everyone, this is my first time posting in the tech talk section. I've been messing around with MEL Script for some time now and one of my buddies suggested showing some of my code to a larger audience to receive better feedback.
I don't necessarily want to learn MEL thoroughly, but it's nice to know enough to be able to enhance my pipeline and get rid of those pesky annoyances that slow things down. That being said, sorry if my code is messy or inefficient. I'm looking for feedback on the general idea of the script, ways to condense/improve code, and whether or not something like this already exists.
I have recently become sick of how Maya handles materials. Max's is so much better, with just a Maps dropdown with all the values and settings right there.
I didn't bother looking up whether a plugin or something already exists for this problem. I'm sure there is, but it's fun to learn how to make my own stuff.
Below is a script I made for automatically applying, naming, and opening the file browser for my selection. I made one of these for each outColor channel I use most, like spec, incandescence, diffuse, and transparency.
$object = `ls -sl`;
proc string findShape( string $object )
{
if ( `objectType $object` == "mesh" )
return $object;
string $shapes[] = `listRelatives -children -shapes -path $object`;
if (`size $shapes`)
return $shapes[0];
else
{
warning "Multiple shape nodes detected!";
return "";
}
}
////Define Assigned Material
$matSelect = stringArrayRemoveDuplicates(ls("-mat",listConnections(listConnections("-type","shadingEngine",`ls -sl -o -dag -s`))));
////Create file node & rename
createRenderNodeCB -as2DTexture "" file "";
$matNormal = `rename ( $matSelect[0] + "_Normal" )`;
$matPlaced = `listConnections -t place2dTexture $matNormal`;
select $matPlaced;
rename ( $matSelect[0] + "_NRM_2D" );
////Create Bump Node & rename
createRenderNodeCB -asUtility "" bump2d "";
$matTangent = `rename ( $matSelect[0] + "_Tangent")`;
setAttr ( $matTangent + ".bumpInterp" ) 1;
////Attach File Node to bump2d node
defaultNavigation -connectToExisting -source $matNormal -destination $matTangent;
////Attach to bump node to bump channel
defaultNavigation -connectToExisting -source $matTangent -destination ( $matSelect[0] + ".normalCamera" );
////select node & assign file
select $matNormal;
AEfileTextureBrowser "AEassignTextureCB ( $matNormal + \".fileTextureName\" )" image;
select $object;
commitAENotes($gAECurrentTab);showEditorExact $matSelect[0];
////NOTE You may receive an error related to the AEfileTextureBrowser. This is simply the search window for when you choose your normal map file. I still cannot for the life of me find the code that loads the AEfileTextureBrowser module. It seems to load into Maya after a file has been loaded for the first time (per session). If anyone knows the script for how to load the AEfileTextureBrowser, I would greatly appreciate it.
Despite the error, if you inspect your material attributes you should see your Bump channel has been assigned with some appropriately-labeled nodes.
DOUBLE CLICK MENU (reverses the above--deletes all child nodes attached to the .normalCamera channel
$object = `ls -sl`;
proc string findShape( string $object )
{
if ( `objectType $object` == "mesh" )
return $object;
string $shapes[] = `listRelatives -children -shapes -path $object`;
if (`size $shapes`)
return $shapes[0];
else
{
warning "Multiple shape nodes detected!";
return "";
}
}
//double-click to remove map
$matSelect = stringArrayRemoveDuplicates(ls("-mat",listConnections(listConnections("-type","shadingEngine",`ls -sl -o -dag -s`))));
$matBump = `defaultNavigation -defaultTraversal -destination ( $matSelect[0] + ".normalCamera" )`;
string $deleteChan[] = `defaultNavigation -defaultTraversal -destination ( $matSelect[0] + ".normalCamera" )`;
string $delete2d[] = `listConnections -t place2dTexture $matBump`;
string $deleteBump[] = `listConnections -t bump2d $matSelect`;
select $delete2d[0];
doDelete;
select $deleteChan[0];
doDelete;
select $deleteBump[0];
doDelete;
select $object;
commitAENotes($gAECurrentTab);showEditorExact $matSelect[0];
Thanks!
Replies
(tried copying and pasting the top script, and got errors)
// Error: AEfileTextureBrowser "AEassignTextureCB ( $matNormal + \".fileTextureName\" )" image;
//
// Error: Wrong number of arguments on call to AEfileTextureBrowser. //
I still cannot for the life of me find the code that loads the AEfileTextureBrowser module. If anyone knows the code for how to load the AEfileTextureBrowser, I would greatly appreciate it.
If you inspect your material attributes you should see your Bump channel has been assigned with some appropriately-labeled nodes.
Tried sourcing it in the script and still nothing. Maybe its how the arguments are constructed though I still think creating your own file dialog and customizing it would be the best way. Future proofs when random mel scripts decide to disappear from the AETemplate folders :P