I am new to writing scripts for maya and have run into an issue in an expression i am writing. I need an object at translateX=1 to trigger the accelerated spinning of another object. I want it to accelerate for 20 seconds and then continue spinning at the new constant velocity. I realize that I have other issues in my script, but I am trying to tackle them one at a time. When I run the script from the expression editor, it tells me that I haven't declared the variables, though it seems to me that I have. I have spent hours and hours trying to figure out what I'm missing or doing wrong and have simply been unable to understand. I have written other, smaller scripts that worked fine, but must be doing something different here. I hope that someone could shed some light on things for me. Thanks in advance for any help. Here is what I have so far...
one other thing if someone wanted to help to grasp the issue, is that the script editor tells me that maya doesn't like the reassignment of the rotationZ values to the old rotateZ value times something or plus something such as.....
why wouldn't it allow me to do this...it seems to be a reasonable function to me...thanks for anyone willing to explain so i can get a better grasp of things.
When doing comparisons between variables you need to remember to use == instead of single = Regarding the problem with variables which are not initialised it is because you initialise the variables inside the scope of the first if. Therefore the variables will not be declared in the second loop.
What you could do is to move the declaration of the variables outside the first if, and then set the variables inside the loop.
Regarding the assignment to rotateZ in the script editor, I assume you should use setAttr instead meaning: turbine_L.rotateZ = turbine_L.rotateZ + $acceleration; changes to setAttr turbine_l.rotateZ (getAttr turbine\_L.rotateZ + $acceleration);
Thank you so much...that was so helpful. I didn't realize that the declaration had to come either within a loop to be only valid in the loop or outside the loop. I was trying to write the script as an expression, which I thought used the notation that I was using for the rotateZ, but I guess I was confused. I can definately change it over to the MEL script with the setAttr and getAttr.
oh...ok...thanks for the clarification.... I actually have another question real quick if anyone knows how to make a variable that will round to the nearest whole number. I know if I assign an int variable to an equation that actually solves to a decimal that it will by default round down. Does anyone know who to set it so that it will round to the closest rather then just down. thanks.
ok, quickly form the top of my head, cant remeber maya having orther round operators except floor an ceil, can be wrong tough. It can be made a bit more efficent too without using a if switch.
ok...awesome...thanks... i have done extensive work on this script and it vastly improved from above, but i still have one issue when i go to execute the file. i am apparently calling the attribute values incorrectly or something because i get an error that the following is unacceptable:
$rotationL_set = 'getAttr turbine_L.rotateZ';
i thought that this line would assign the current value of the rotate Z of the turbine_L to the variable $rotationL_set. Apparently i'm mistaken. can anyone clarify why i can't do this or how to properly do this. thanks so much
Its how it is ecaluated. Because you use getattr then maya might skip evaluation of this term on demand and only do this once per frame beause its not a direct connection and makes maya blind of its evaluation. IN general one should never use GetAttr or settattr in a expression unless you know exaxtly why your doing so, and what implication it will have to your script.
thanks so much for replying so quick... i get what your saying...but have two issues with it... first is that i have tried it and still get an error that says it is an invalid use of the maya object turbine_L.rotateZ second is that i thought that in Mel you were unable to directly access this information and had to call up the value instead of using it directly like you can in the expression editor.... clarification would be great....i'll post the beginning of the code since i updated but before i changed over the getAttr and setAttr over to the way that just described to me...its just the beginning of the code, so loops may seem open and stuff but you may be able to make things clearer for me if you actually see what was written....thanks...
sorry my mistake i tought you were actualy deveopping a expression. now that i look at it more carfully you have a stupid error.
your using ' instead of `(backtick)
Also your code looks like you wnat a expression not mel.
one note on your code. Its not terriby good. What youd better do is make a array and store the data in one of thso einstead of having a gigantic amount of variables around.
thats such a stupid error...thats funny....thanks.... i definately realize that the code is pretty bad....but i am completely new to writing code for maya and had to try to get something that would just work for now....though i would like to try to improve it ...but that would have to be later unfortunately...i'll definately try the array method...right now i don't really know how i would approach that, but i'll read up on it and see if i can tackle that later.... thank you again so much for your help...i really do appreciate it