PDA

View Full Version : preseting and changing variables


Phugative
11-15-2003, 03:27 AM
I want to create an object first with preset values then a window in which the user can reset the values to modify that object.

Right now I have a window that takes user input then creates the object via a button. The values are variables that query sliders then input them into expressions that control the object. This works great except you obviously can't change the values after the object has been created.
So how do I set it up so that the object is created with preset values that the user can then change?

My problem is that I can't create a object that takes its values from variables that depend on a sliders in a window if that window is not yet created. How do you put a value into a variable, but then have that value change later depending on user input?

It seems simple enough but I can't seem to set it up correctly.

brubin
11-15-2003, 12:51 PM
Originally posted by Phugative
I want to create an object first with preset values then a window in which the user can reset the values to modify that object.

Right now I have a window that takes user input then creates the object via a button. The values are variables that query sliders

well, if you query you can't set.



then input them into expressions that control the object. This works great except you obviously can't change the values after the object has been created.
So how do I set it up so that the object is created with preset values that the user can then change?

the solution is "connectControl". look it up in the docs, and search the native maya-script for examples on how to use it. it can be done, but it's not reaaaally easy...



My problem is that I can't create a object that takes its values from variables that depend on a sliders in a window if that window is not yet created. How do you put a value into a variable, but then have that value change later depending on user input?


which is it now? i understood, that the window creates the object? or is it a shelf button? if so, you have 3 options: include the create-object-button into your window-interface and get rid of the shelfbutton.

or you set "optionVar"s for defaults inside you button's mel-definition.
read those out when you click-create your object. open the window and change 'em. you can do 3-liners like :

string = $myDefaultValue ;
if (!`optionVar -exists "myDefaultValue"`)
{
$myDefaultValue = "hello" ;
optionVar -stringValue "myDefaultValue" $myDefaultValue ;
}
else $myDefaultValue = `optionVar -query "myDefaultValue"` ;

or you write your defaults into a <object-name>.defaults.mel that gets sourced when you click your create-button. the script sets (global) variables for your object.
global variables can then be changed/updated later anytime.

HIH
s.

Phugative
11-15-2003, 06:58 PM
brubin-
To answer your question-
A button in a window creates the object, it is not a shelf button.

I understand the connectControl command, but how would I connect a slider to a certain numeric value inside part of a runtime expression?
Say that value is represented by a variable that gets its value querying a slider in the window. Following this chain of thought, when the slider is changed, in turn the value and thus the expression is changed in realtime during a simulation.

I just don't know how to set that up, where does the query expression for the slider go? Also the same problem with default values arise. I don't want a create button in the window, I simply want the user to tweak a slider and see the result. So I need the values for the expressions or objects preset, then changed when the slider is changed. I want the simulation to begin when you run a script, then a window opens that controls the simulation.

Could i use the default naming methods you mentioned above to accomplish this? I can post sample code too if that would help. Thanks for your help. i hope this makes my problem more clear to you.

brubin
11-15-2003, 07:26 PM
Originally posted by Phugative
brubin-
...I can post sample code too if that would help. Thanks for your help. i hope this makes my problem more clear to you.

no, not really, -post some example,
describing what happens first, where the window comes in, what the user is supposed to do with it...

cheers,
s

Phugative
11-15-2003, 09:25 PM
I attached the script.
Some things to explain:

Since I do not want to actually have the user create the snow (you will see) the only working part of the variables linked to sliders is the opacityPP part of the expression. I haven't bothered to get the whole UI working, since I want the interaction to happen after a default snow maker has been made.

I have more code that controls the snow but haven't integrated it yet b/c I am having this problem with linking the sliders. Thanks for your input.

brubin
11-16-2003, 11:33 PM
hi,

that's a beautiful interface you created;
I'd sure like to see it when it's finished! (nudge-nudge, know what i mean? :))

at this stage i can't really do much with it, since there are too many strings cut - i can't really test too much of what it does.

nevertheless, today (sunday) it rained, so i sat down and wrote a little something together for you to check out, maybe it gives you some clues.

unzip, install the script into your <script-dir>;
source hop.mel ;
hop;

when the window pops up, you have no object.
click on "have a ball";
click on "play";
slide them sliders around from side to side;

check the expressionEditor.

you can set keys on the first 3 sliders ("nix!" means nothing, the button does nothing so far); these keys come in effect once you kill/close the interface/UI/window., meaning - you can have both: tweak values with expressions via UI-sliders, and also animate accellerations/decellerations.
reopen the window ("hop"), and the expression takes over again, without destroying the animation on the keyframed attributes.

enjoy!

HIH
s.

(inspiration for the script below:)

:bounce:

p.s.: found a little bug, so i updated to v.1.1;
now the nix!-button resets the orientation-attrib. when you close the window with the close-button ball.orientation is set to the last value of the slider.
otherwise doing all this animating with the sliders doesn't make much sense, now does it?
now v.1.2 - some more improvements and 1 minor bug fixed.

CGTalk Moderation
01-16-2006, 05:00 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.