View Full Version : simple mel script - randomizing colors
I created a simple mel script that randomizes slight color offsets for a file texture.
What I want to do is having about 20 same characters in a scene, I want to randomize their colors a bit, just by clicking a mel script. I succesfully created such script that works for one character, but I would like to import many characters to one scene and make the script work for all of them. The problem is that whenever I import a new one it adds the prefix to the object name e.g importedObject1:myobject , importedObject2:myobject etc..
How can I make the script work for each of those?
Also while Im at it - how can I take the endTime from my Timeline? I dont know what its called - I want another attribute to update automatically according to what the End Time of the animation is set to (on the timeline).
06-01-2007, 05:41 PM
There are quite a few ways you can achieve what you are trying to do.
First off your objects are being put into a namespace. I would suggest importing them with a namespace that you know about.
i.e. Import them through mel or type a string in the import window.
This will make life easier for you since you know what the namespace is going to be as well as each materials name that you need to edit. If you have those two things its as easy as looping through each namespace and material and setting the value that you get returned from your random procedure.
If you don't know what the namespaces are then I would suggest probably using the namespace command to get all the namespaces in the scene (theres a lot) and then looping through till you get a match for your material. If you can control the names then it will be a lot easier.
Search the help for namespace command.
For the time I usually use playbackOptions -q -maxTime (and minTime). There are a few ways to get the time, this the command I tend to use. Also, it returns a float since you can have floating point time values.
Best of luck,
Can i use this playbackOptions inside an expression? If so than how?
I'm pretty new to expressions and Mel scripts and I know that they are not the same.. but don't know how to use something that I would use in Mel script inside an expression...?
06-01-2007, 08:13 PM
Depends on what you are doing.
A. Create a seperate variable of your command where you need the time.
ex. float $getEndTime = `playbackOptions -q -maxTime`;
setAttr "Blah.blahAttr" $getEndTime;
Thats a simple one
B. Use the return of your query in a command.
setAttr "Blah.blahAttr" `playbackOptions -q -maxTime`;
The example however will not work if you are trying to use a return within a return
Does that make sense?
06-02-2007, 06:19 AM
If you are looking for really easy, there is a way. You need to know that you can't simply change a color attribute for one singular object because it would use the same shader node, but what you can do is have ambient lights effect only one object or a few objects, this way you can have the same shaders on all the characters and all you need to do is have a few lights to illuminate specific objects. Only problem with ambient lights is that it takes longer to render then any other light. But it would be the easiest. What you can do is parent up directional lights with the camera to always face the character it's effecting, simply orient constraint would work nicely for that. The upside to using directional lighting as well is that you could effect only the diffusion or only the specular information on the shader for the characters, that way you could get a hue difference between characters rather then a full on color change.
How do do this, in the Render menu set - Lighting/Shading > Light Linking Editor > Light Centric, and all you'd need to do is select your light on the left side and unselect everything but the objects you want the light to shine on. Change the lighting propperties and you are golden.
Not to mention the ammounts of other things you can do with this technique.
Thanx kwood thats exactly what I needed - I just didnt know that putting it inside `` returns the query... like I said - I'm a noob in expressions.
@trancor - it's not exactly like that - when I import each character seperately, it gets it's own shader node, and its own material node. I'm affraid that putting so many lights into a scene in case of 20-40 chcaracters would be too much for the renderer. Also the whole reason why I'm asking is to automate the whole thing, so that I don't have to click each character and put in some random values.
Anyways I solved this problem differently - my script works when I just select all the textures that I want to modify, than select the attribute/attributes of these textures in the channel box and click the script button - it works well and is fairly quick.
Thanx for all the help
06-02-2007, 03:12 PM
well, I was just commnig up with another option for ya.
06-02-2007, 03:12 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.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.