Introduction to Maya - Rendering in Arnold
This course will look at the fundamentals of rendering in Arnold. We'll go through the different light types available, cameras, shaders, Arnold's render settings and finally how to split an image into render passes (AOV's), before we then reassemble it i
# 1 17-02-2012 , 10:41 AM
Registered User
Join Date: Jan 2012
Posts: 43

Help with renaming

Hi there.
I don't know crap about mel.
BUT I'm asking anyway, I have a script that assigns new materials from a selection and renames them based on the object's names.
It's almost perfect from my use, but I need just one more thing to save hours of mind numbing work, a string that changes the first letter of the materials name to an uppercase, this way I have no duplicate names and no numbers as a postfix to material's names.
I have ZERO idea on how to do this, so here's the script (it's not mine I salvaged it from some other guy and modified it a bit)

string $nodeName[] = `ls -sl`;
string $matName, $sgName, $fileName;
for($i=0; $i<size($nodeName); $i++)
{
$matName = `shadingNode -as phong -n ($nodeName[$i])`;
$sgName = `sets -renderable true -noSurfaceShader true -empty -name ($nodeName[$i] + "SG")`;
connectAttr -f ($matName + ".outColor") ($sgName + ".surfaceShader");
select $nodeName[$i];
sets -e -forceElement $sgName;
}
clear $nodeName;

//script by Paul Lohman

Any help much appreciated really, this would make my life a ton easier..

# 2 17-02-2012 , 01:25 PM
EduSciVis-er
Join Date: Dec 2005
Location: Toronto
Posts: 3,374
My convention that I've seen elsewhere is to have an M at the end of the name, e.g. floorM (for material). That would be easier to append than changing the case of the existing string.

# 3 17-02-2012 , 04:04 PM
Registered User
Join Date: Jan 2012
Posts: 43
I have no choice, I can't change the naming convention. It's not my decision to make.
We use camelcase, but no uppercase for the name of the objects.
But the names of the materials needs to have full camelcase, like this:
someObject ->obj
SomeObject ->mat
I have to assign a material per object with the freakin uppercase, can't avoid that.
Seems like nothing but I can't just copy the name with the script thus keeping me from "one button press bliss" and into "spend precious minutes doing repetitive crap hell". Story of my life :]

# 4 19-02-2012 , 10:56 PM
NextDesign's Avatar
Technical Director
Join Date: Feb 2004
Posts: 2,988
So you want it to automatically find words in a string, and camel case them? This would take forever in a scripting language, as it would need to run through a large dictionary of words, and compare them. Changing the first letter to upper case in a material though, is simple.

Code:
string $name = "thisisatest";

int $nameSize = `size $name`;
string $firstCharacter = `substring $name 1 1`;
string $rest = `substring $name 2 $nameSize`;

string $newName = `toupper $firstCharacter` + $rest;

print ($newName);

// Result: Thisisatest


Imagination is more important than knowledge.
# 5 20-02-2012 , 05:18 PM
Registered User
Join Date: Jan 2012
Posts: 43
This script is exactly what I need!
I'm ashamed to ask but I have no idea how to use it.
Would it be possible to merge it with the first script just as to uppercase the first letter of the material?
That would save me a lot of time and possibly the rest of the team too.

# 6 21-02-2012 , 06:24 AM
NextDesign's Avatar
Technical Director
Join Date: Feb 2004
Posts: 2,988

Would it be possible to merge it with the first script just as to uppercase the first letter of the material?

Of course. Give this a try:

Code:
string $nodeName[] = `ls -sl -tr -dag`;
string $matName, $sgName, $fileName;

for($i=0; $i<size($nodeName); $i++)
{
    $matName = `shadingNode -as phong -n ($nodeName[$i])`;
    $sgName = `sets -renderable true -noSurfaceShader true -empty -name ($nodeName[$i] + "SG")`;
    connectAttr -f ($matName + ".outColor") ($sgName + ".surfaceShader");
    select $nodeName[$i];
    sets -e -forceElement $sgName;

    int $nameSize = `size $matName`;
    string $firstCharacter = `substring $matName 1 1`;
    string $rest = `substring $matName 2 $nameSize`;

    string $newName = `toupper $firstCharacter` + $rest;

    rename $matName $newName;
}

clear $nodeName;
I've also changed the way $nodeName is populated. The way you had it, `ls -sl` would grab all selected nodes, not just geometry. I switched it to `ls -sl -tr -dag` to fix this. It means that it will grab all transform dag nodes for you.

Hope this works for you.

-John


Imagination is more important than knowledge.

Last edited by NextDesign; 21-02-2012 at 06:31 AM.
# 7 21-02-2012 , 03:27 PM
Registered User
Join Date: Jan 2012
Posts: 43
Awesome, it's working perfectly!
Thanks a hundred times, approximately the number of hours it will save me!

Vive le Canada! Merci vraiment c'est la super classe!

# 8 21-02-2012 , 04:49 PM
NextDesign's Avatar
Technical Director
Join Date: Feb 2004
Posts: 2,988
Haha. Thanks a lot mate. Glad it's working for you.


Imagination is more important than knowledge.
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads