PDA

View Full Version : MaxScript: detecting selectionset change


Marcel
01-19-2003, 12:01 PM
I'm trying to figure out how to detect a selectionset change from within a script.
I have a slider that displays the x position of the selected object (or selected vertex). When I change my selection I want to blank out the slider with the slider.indeterminate = true option.


According to the help files this line of code should run my function 'func_clear_slider' whenever the selectionset is changed:
callback.addScript #selectionSetChanged "func_clear_slider()" id:#myscript_update

And for the sake of decency I should remove the callback when I close the script with this line:
on cn_floater close do callback.RemoveScripts #selectionSetChanged id:#myscript_update


With my limited coding skills I would envsion the called function to look a bit like this:
function func_clear_slider =
(
myscript_spinner.indeterminate = true
)

However, when I put all this code in my script nothing happens when I change my selection set. The scary thing is... I don't even get an error message :)

Any MaxScripts Guru's around who know how to do this, or point me to a MaxScript that already does so I can see how it's done?

Many thanks in advance!

Marcel
01-19-2003, 12:36 PM
Another question: is there a way to update the scale property for a slider so that I can adjust it's sensitivity after it has been created?
Having a slider react the way a normal UI slider does would also be perfect (I mean increasing the step size when the value is higher and vice versa).

Bobo
01-19-2003, 12:56 PM
First of all, it is callbacks and not callback.
Then, you have to make sure that the function is accessible through the global scope. Either define the function im global context, or define the rollout the function is contained in as a global variable and let the function call follow that path...

The first would be better when the function does some general work that is not specific for a single script and could be accessed from multiple scripts...

The second way is better when it comes to local UI changes.

An example:

macroScript test category:"Tests"
(
global my_test --global rollout variable
rollout my_test "Test"
(
spinner myscript_spinner "Test"

--the function as you know it...
fn func_clear_slider = ( myscript_spinner.indeterminate = true )
--remove the callback when closing the rollout:
on my_test close do
callbacks.RemoveScripts #selectionSetChanged id:#myscript_update
)
--create a dialog from the rollout
createDialog my_test 200 100
--add the callback script. Note that the function call mentions the gloabl rollout variable to show the path to the function...
callbacks.addScript #selectionSetChanged "my_test.func_clear_slider()" id:#myscript_update
)--end script

Be careful to give the global rollout variable a longer name than just "my_test" to avoid conflicts with other scripts!

Bobo
01-19-2003, 01:02 PM
Originally posted by Marcel
Another question: is there a way to update the scale property for a slider so that I can adjust it's sensitivity after it has been created?
Having a slider react the way a normal UI slider does would also be perfect (I mean increasing the step size when the value is higher and vice versa).


Unfortunately no.

Look at the MAXScript Help - Spinner.
You will see the constructor of the class, then a list of PARAMETERS, then a list of PROPERTIES.

Parameters are the values you can specify in order to define the appearance and functionality of the UI item at CREATION TIME.

Properties are the values accessible for the UI item at RUN TIME.

So you can only CHANGE Properties but not Parameters.

A possibility would be to rebuild the whole UI on the fly when you need a change of parameters not accessible as properties... But this is hard and does not solve your specific problem with the spinners.

Marcel
01-19-2003, 02:56 PM
I will print out your avatar and worship it as my new god! It works!

Thanks BoBo, your help was invaluable. I wouldn't have gotten it to work without your example.

One more question: Is there any way to detect a change in the vertex selection of the object? Right now changing to another object works perfectly, but selecting other vertices (in the same object) doesn't trigger the clear_spinner function.

Also, when I take the focus of a floater window with radiobuttons (click in the viewport for example) and select the floater again again, then the 'radiobuttons changed' is triggered. Is that a bug, or is it part of some grander scheme I cannot comprehend right now? :)

So you can only CHANGE Properties but not Parameters.

I suspected so much about the spinner.scale parameter. Now I know for sure. It's a shame that the spinners cannot be set to function as the normal UI spinner.

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