I have written a simple expression that makes an object turn on (visibility) in relation to time and its distance from the Y axis. Now I want to apply that same expression to hundreds of other objects in the scene- it is a scene with a huge field of hexagons and i want them to all blink sequentially from left to right. It's working, but i am wondering if i can do it far more effieciently.
Well I can't make out exactly what you're trying to declare with those variables in the expression up there (divisors.frameDiv??) but in order to apply an expression to all the mesh objects in your scene just use the following simple script:
CODE string $sceneObjects[] = ls -type mesh; int $count = 0; for ($i in $sceneObjects) { expression -s ($sceneObjects[$count] + ".visibility = 0;") - o ($sceneObjects[$count]) -ae 1 -uc all; $count++; }
and dont forget to replace the ".visibility = 0;" part with your working expression. Run this once and all your objects visibility will be set to be controlled by your expression.
// Error: Attribute not found or variable missing '$': translateX //
Your script didn't work for my particular problem because, I think, it wants to know which object's "translateX" attribute to change, and of course I can't write "polysurface2.translateX" into every expression, because it needs to be different for each object; specifically, it needs to change depending on each object's individual translateX. Is there any way to write "polysurface"*(wildcard or something)".translateX?
If I just copied your script the way it was, it worked, but of course it just made the visiblity of all of the objects "0". Also, it doesn't attach the expression to the objects .visibility channel in the channel editor, but rather affects the visibilty radio button in the Object Display portion of the attribute editor. That's not necessarily a bad thing, it just freaked me out- i was like, where did everything go?!
By the way, the "divisors" node is an empty node which has two custom attributes, frameDiv and txDiv. This is just a place I can put 2 integers which will be attached to all of the expressions, so if, for example, I want to change the factor by which I am dividing the frame for ALL the expressions, I just change the value in divisors.frameDiv instead of doing them all individually.
Any more help and I'm sending you donuts, Cameron
ps where did you learn how to mel script? I wanna do it too!
Well you had that error because the syntax of your expression is wrong. The visibility attribute can either be 0 or 1 , thus I believe that there is a problem with your expression as under various circumstances it probably gives very different results from 0 or 1.
Anyway here is a script that takes into consideration the translateX of the object along with your divisor node data:
CODE string $sceneMesh[] = ls -type mesh; select ($sceneMesh); pickWalk -d up; string $sceneObjects[] = ls -sl; select -cl;
Now this is the only visibility attribute I know of, and when you run the script you do see in the Channel Editor that this atrribute is controlled by an expression.
Theres a more elegant solution. Wich can aslo animate soem behaivour for those hexagons winking in , for example they could flash in a rapid succession when they are about to phase in.
Now ths is most easily done by using a shading switch wich is added to the time attribute wich is then triven to aramp thet represents the animation sequence. This only works when rendering out so teh feedback is rather minimal whan switching in. I think i have example of this here: Appearing balls.
If the gons are all identical you can also try to use a instancer tat cycles a few differently shaded hexagons now thsi has the added advantage of ginving very good feedback and your time. A 3rd one is to have a specialy coregraphed loopup map thats projected on the hexagons giving you a on map controll oever the values. In both particles and the map cases you could then PAINT the sequance into randomity if you wished!
The part I'm working on now is the Blue hexagons in the middle part. You can see what I want them to do in my maya project which I am going to post shortly, as soon as this friggin webhosting co. calls me back.
so Segmoria, i tried your new script and got this error:
well adding the attribute and setting it by script is not realy a trick! I actualy have a simple halfinished script that adds the attributes just by assigning a material with switches. Anyway its a simple for loop
could you post ma instead of mb because mb contains a rather nasty security problem.
Anyway you can use objects traslate value instead of a custom attrib!
heres a better example that uses the x position of the obhjects to drive their color trough a ramp i use the x value as their u valiues so you could concievably connect some noise in too now you KNOW how to animate a ramp!
Note this is just a scene i made a trascript off, warning it erases what you have!:
Note each sphere has a single color so, also you could shift in the drive. And as i said driving in the ramp + noise fed by teh switch as u would cause soem randomity!
You are the man for you help. However, your scripting is way beyond my knowledge. I know how to copy and paste a script, and that is it. I understand that it is possible to set an attribute and assign a material with a loop with a "simple" script, but i have absolutely no idea what to write to make that happen. I want to learn more about scripting, i just haven't had a chance and I usually don't need to do it...
However, I am sure there has got to be some simple solution to my problem- check out the current project above. I need to make thousands of hexes do what the hexes in that project are doing - blinking sequentially depending on their x-position. I managed to make those 20 or so hexes do it, now I am just looking for a way to apply that same expression to a shitload of other hexes.....
okay you have frozen the data! maybe ist just a planar trim?!? Well the copypaste scripting sisnt as hard as people think. Anyway is there some specific reason wyyoud want to keep the novisile faces?
anyway the simplest form ao for aloop is for ($item in ls -sl){ //loop tough all selected objects print $item; // do something to item }
anyway theres a few siple things you can do to the scene... but im super busy today!
PS FInland, it reads in my profile, you can invoke it by clicking my name in posts!
PPS there swas slight bug in the example! fixed it. (the callback isnt loaded untill you loas teh aetemplate for a switch)