View Full Version : find ":" in shadernames and delete out ?!


Inlakechh
09 September 2007, 11:28 AM
Hi,

I just started with MEL scripting an have 2 little problems that I just find no solution for.


1.
My script takes all used shaders in the scene, creates new shaders with part of the old names and assigns the new shaders to the selections the old shaders have been on.
The problem is the ":" in previously imported shaders that cause the script to stop as when creating the new shaders it names them only with the part following the ":" and cannot assign them because the names (Variables) are different.

Easy said: In the beginning of the script I need Maya to search for ":" in the shaders name end erase it out. How can I do that?




2.
- I'm creating vector values with the Sphrand command to assign them to the R,G and B color attributes of a new generated shader.
Whenever a value is negative it causes the shader to look black. So I'm looking for a way to make the Sphrand Values always positive. Here's my idea:

vector $randomPos =sphrand (1);
if ($randomPos.x<0)
($randomPos.x) = ($randomPos.x) *-1


Maybe it's just Syntax error, but I dont know whats wrong. I'm trying to multiply the x value of the vector by -1 if its smaller than zero to get it positive. I'm going to repeat this for y and z when it's working.


I really appreciate any kind of help.
Thank you very much in advance.

Buexe
09 September 2007, 02:17 PM
to 1)

string $name = "hallo:tollerShader";

//declare an array to put your item into
string $buff[];

// split the string into parts divided by ":"
tokenize $name ":" $buff;

print $buff;

//This is what you want
string $shortName = $buff[1];

for 2.)
check the clamp command, this will make sure your values are within a given min and max.

Inlakechh
09 September 2007, 06:18 PM
thanks alot ... I'm not sure how to let maya know, when to search for the ":" ... but gonna try it out.

trancor
09 September 2007, 03:39 AM
Wild cards are your friend in any language.

Just try "*:*" to find any node with that name, you could always find shade nodes specificly by doing "*:*SG" or to list node types for shaders.

Inlakechh
09 September 2007, 09:24 AM
Thank you,

but which command do I use to query if ":" is inside a Nodes Name ?
putting *:* gives me a result in the hypershade but even the output code with "echo all commands" gives me no hint.


Regarding the clamp node for use with my negative Sphrand values. I guess it is going to turn them to 0, but I'd just like the minus in front of the number to switch to a positive.
-.543 to .543.



You see I have ideas how to solve things ... I'm just still lacking commands to use.
Please give me another hint.

Thank you guys.

Buexe
09 September 2007, 11:19 AM
In the MEL docs there is a section dealing with strings check match, gmatch etc.
The tokenize command retruns how many poeces it cut the string into so when it gives you two strings back you know there must have been a ":" or whatever in your string.

Inlakechh
09 September 2007, 02:41 PM
Wooo, it's working :bounce:.

gmatch in combination with tokenize, Nodelock and rename is a great solution Buexe !!

I found a solution for the Sphrand issue with negative values aswell.
Using the absolute (abs) command returns only positive values.

Thanks again for making my start in Mel quite comfortable with this help :thumbsup:.

Buexe
09 September 2007, 05:23 PM
proesterchen! : )

isoparmB
09 September 2007, 03:38 AM
Regarding the namespace issue, you can use this script:

http://highend3d.com/maya/downloads/mel_scripts/utility_external/misc/nameSpaceRemover-3730.html

Just make sure there are no referenced objects in your scene.

Buexe
09 September 2007, 08:44 AM
Thanks for the link and the script isoparmB! Looks very promising and helpful, I`ll check it out!

CGTalk Moderation
09 September 2007, 08:44 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.


1