Scripting-noob has questions

Hi guys,

I'm new to this forum (and scripting in general) but decided to take the plunge and learn. I'm trying to write a script that randomly scales objects between two values, using the very basic Maxscript-knowledge I have right now.

I run into two problems:
- When the rollout opens, I'd like the default values to be set to 0.9 for 'min' and 1.1 for 'max', but can't get it to work.
- When I use the current rollout, and don't change the values, the scaling goes hopelessly wrong. Even though the spinners say 0.9 by default, it seems to be using '0.0' as a default
- Is there a way to use three digits after the komma?

Thanks a lot, I'll post the code below.

--------

MacroScript Randomize_Hanging_Product category:"Swillie's Scripts" buttonText:"Randomize Hanging Product" tooltip:"Randomize Hanging Product"
(
rollout RandomizeRollout "Randomize Hanging Product" width:226 height:150
(
spinner spn1 "Min" pos:[15,59] width:58 height:16 range:[0.9,1.1,0]
spinner spn2 "Max" pos:[15,78] width:58 height:16 range:[0.9,1.1,0]
spinner spn7 "Min" pos:[90,59] width:58 height:16 range:[0.9,1.1,0]
spinner spn8 "Max" pos:[90,78] width:58 height:16 range:[0.9,1.1,0]
spinner spn9 "Min" pos:[165,59] width:58 height:16 range:[0.9,1.1,0]
spinner spn10 "Max" pos:[165,78] width:58 height:16 range:[0.9,1.1,0]
label lbl6 "X" pos:[43,35] width:16 height:18
label lbl7 "Y" pos:[118,35] width:16 height:18
label lbl8 "Z" pos:[193,35] width:16 height:18
button btn8 "Randomize!" pos:[43,108] width:140 height:18
button btn9 "Clear" pos:[43,130] width:140 height:18

on btn8 pressed do
(
for obj in $ do
(
if (selection.count > 0) then
(
randXscale = random spn1.value spn2.value
randYscale = random spn7.value spn8.value
randZscale = random spn9.value spn10.value
scale obj [randXscale,randYscale,randZscale]
)
else
(
messagebox "Je hebt niks geselecteerd, joker!"
)
)
)

on btn9 pressed do
(
spn1.value = 0.0
spn2.value = 0.0
spn7.value = 0.0
spn8.value = 0.0
spn9.value = 0.0
spn10.value = 0.0
)
)
createDialog RandomizeRollout 226 150
)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Anubis's picture

Hi Swillie, all you need is

Hi Swillie,
all you need is described in the help. the range property hold [min,max,val] where 'min' and 'max' define you range and the 'val' is the default value. In you case that w'd be "range:[0.9,1.1,0.9]". That's it.

And also each spinner has 'scale' property which give you a desired precision without messing with the global settings (preferences.spinnerPrecision). So here is example spinner:

spinner spn1 "Min" pos:[15,59] width:58 height:16 range:[0.9,1.1,0.9] scale:0.01

Cheers

my recent MAXScripts RSS (archive here)

Swillie's picture

Thanks!

Thanks!

Swillie's picture

Hi man, thanks for helping.

Hi man, thanks for helping. Unfortunately I don't quite understand

- What's with the [0.154324,10.1,0.9] and [0.121123,10.1,1.1]? I want it to range between 0.9 and 1.1, how does this apply? And why the extremely precise but seemingly random numbers?
- How do I use preferences.spinnerPrecision ? In other words, how and where do I put in into my code? Doesn't seem to work when I try it.

Many thanks for your patience, I understand that for experienced scipters these questions might be a pain :)

Graph's picture

spinner spn1 "Min"

spinner spn1 "Min" pos:[15,59] width:58 height:16 range:[0.154324,10.1,0.9]
spinner spn2 "Max" pos:[15,78] width:58 height:16 range:[0.121123,10.1,1.1]

and

preferences.spinnerPrecision

This integer value defines the number of decimal digits displayed by spinners.
Corresponds to the Precision value in the Spinners group in Customize > Preferences > General.

Raphael Steves

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.