Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / Add different preset values to spinners when clicking a button...?
  RSS 2.0 ATOM  

Add different preset values to spinners when clicking a button...?
Rate this thread
 
46631
 
Permlink of this thread  
avatar
  • Total Posts: 31
  • Joined: 15 October 2007 06:09 PM

Hi All

i’m trying to have a set of spinners which i can update with preset values by clicking different buttons.....

ie. click button1 to update spinnerA with 1.0 spinnerB with 0.5 etc.
click button2 to update spinnerA with 0.5 spinnerB with 1.2 etc.

do you know if this is possible? cannot seem to find any way to do it....

thanks in advance :)

Neil



Replies: 0
avatar
  • Anubis
  • Posted: 27 August 2010 12:49 AM

utility test "Test"
(
   
fn preset1 val1 val2 = (val1 1.0 val2 0.5)
   
fn preset2 val1 val2 = (val1 0.5 val2 1.2)

   
spinner spnA "A:" range:[0,100,0]
   spinner spnB 
"B:" range:[0,100,0]

   button btnP1 
"Preset 1"
   
button btnP2 "Preset 1"

   
on btnP1 pressed do ( preset1 spnA.value spnB.value )
   
on btnP2 pressed do ( preset2 spnA.value spnB.value )
)


Max 9 through 2009, XP-Pro x64 SP2
ASUS EAH3450 Series (Driver 8.470).
Core 2 Duo E8400 3GHz, 4Gb Ram, DX9.0c.

Replies: 3
/img/forum/dark/default_avatar.png

Would those function params not have to be “in” (or “out") values - passed by reference not by value? Not sure if you can pass object properties as references though - would have to test that.

Author: Steve_Curley

Replied: 27 August 2010 01:14 AM  
/img/forum/dark/default_avatar.png

Ok, it does work, if the params are by reference.

utility test "Test"
(
   
fn preset1 &val1 &val2 = (val1 1.0 val2 0.5)
   
fn preset2 &val1 &val2 = (val1 0.5 val2 1.2)

   
spinner spnA "A:" range:[0,100,0]
   spinner spnB 
"B:" range:[0,100,0]

   button btnP1 
"Preset 1"
   
button btnP2 "Preset 1"

   
on btnP1 pressed do ( preset1 &spnA.value &spnB.value )
   
on btnP2 pressed do ( preset2 &spnA.value &spnB.value )
)
Author: Steve_Curley

Replied: 27 August 2010 01:39 AM  
/img/forum/dark/default_avatar.png

Thanks for the reference variables correction Steve. I forgot to test my example ;)

Author: Anubis

Replied: 27 August 2010 09:02 AM  
avatar

thanks for the response, however i cannot seem to get this to work.....
i just added the code to dispaly the dialog.... but the buttons do not respond, do you have any idea why?

thanks again :) Neil

utility test "Test"
(
   
fn preset1 val1 val2 = (val1 1.0 val2 0.5)
   
fn preset2 val1 val2 = (val1 0.5 val2 1.2)
   
spinner spnA "A:" range:[0,100,0]
   spinner spnB 
"B:" range:[0,100,0]
   button btnP1 
"Preset 1"
   
button btnP2 "Preset 2"
   
on btnP1 pressed do ( preset1 spnA.value spnB.value )
   
on btnP2 pressed do ( preset2 spnA.value spnB.value )

createDialog test 180 450 1350 100


Replies: 0
avatar
  • Location: West Midlands, England, UK
  • Total Posts: 14445
  • Joined: 06 August 2007 11:06 PM
  • Permlink of this post

(
rollout Test "Button Test" width:208 height:108
   
(
   
spinner spn1 "" pos:[25,23] width:61 height:16
   spinner spn2 
"" pos:[122,24] width:61 height:16
   button btn1 
"1.0/0.5" pos:[26,67] width:53 height:22
   button btn2 
"0.5/1.2" pos:[122,63] width:56 height:30
   on btn1 pressed  
do
      (
      
spn1.value 1.0
      spn2
.value 0.5
      
)
   
on btn2 pressed  do
      (
      
spn1.value 0.5
      spn2
.value 1.2
      
)
   )
try 
destroyDialog Test catch()
createDialog Test
)

[edit]:oops: - just saw Anubis’s reply [/edit]



Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.

Replies: 2
/img/forum/dark/default_avatar.png

that’s great, thanks Steve.... this one seems to work fine.... :)

Author: neilcooper33

Replied: 27 August 2010 01:22 AM  
/img/forum/dark/default_avatar.png

The other one would too, with some minor changes. See my comments to the earlier post.

Author: Steve_Curley

Replied: 27 August 2010 01:40 AM  
avatar
  • Anubis
  • Posted: 27 August 2010 10:27 AM

Excuse my stupid mistake above, it come from my working style :)
i.e. my coding declaration goes…

1. Local variables
2. Main Functions
3. UI controllers
-----------------------
4. UI Functions

Usually all functions (in UI’s) are declared before the rollout controllers (alias good practice), but I found as useful to add the functions that control the UI after that with “hard-coding” path to the controllers. This benefit me with more simplified usage of the function inside the code. So, if you find this style useful, here is an example:

if classOf Test == RolloutClass do destroyDialog Test
rollout Test 
"Button Test"
(
 
spinner spnA "A:" range:[0,100,0] across:2
 spinner spnB 
"B:" range:[0,100,0]
 button btnP1 
"Preset 1" across:2
 button btnP2 
"Preset 2"
 
 
fn presets id = (
 case 
id of (
 
1: (spnA.value 1.0 spnB.value 0.5)
 
2: (spnA.value 0.5 spnB.value 1.2)
 )
 )
 
 
on btnP1 pressed  do ( presets 1 )
 
on btnP2 pressed  do ( presets 2 )
)
createDialog Test


Max 9 through 2009, XP-Pro x64 SP2
ASUS EAH3450 Series (Driver 8.470).
Core 2 Duo E8400 3GHz, 4Gb Ram, DX9.0c.

Replies: 0