PDA

View Full Version : random selected keys


arno3d
06-09-2009, 05:43 AM
To randomise keys value I use this command :
for i in $.pos.controller.X_Position.controller.keys do i.value = i.value + (random -1 1)

But how can I randomise only selected keys ?

Thank you

Arno
arno3d.blogspot.com

arno3d
06-09-2009, 05:46 AM
I wrote this little macroscript :

macroScript Random_Pos
category:"- arno -"
toolTip:"random keys Position value for Kaj"
buttonText:"RdPos"


(
try (destroyDialog RandomPosRollout) catch()

rollout RandomPosRollout "Random_Position" width:128 height:200

(
checkbox chk1 "X_position" pos:[32,25] width:84 height:25
checkbox chk2 "Y_position" pos:[32,49] width:84 height:25
checkbox chk3 "Z_position" pos:[32,72] width:84 height:25
label lbl1 "Select Axis" pos:[12,8] width:104 height:14
spinner Param1 "Rand1:" pos:[20,110]Width:80 Height:16 Align:#Center Offset:[-20,0] Type:#float Range:[-100,0,0]
spinner Param2 "Rand2:" pos:[20,130] Width:80 Height:16 Align:#Center Offset:[-20,0] Type:#float Range:[0,100,0]
button Execute "Random !" pos:[32,160]

on Execute pressed do
(
if chk1.checked ==true do
(
for i in $.pos.controller.X_Position.controller.keys do i.value = i.value + (random Param2.value Param1.value)
)

if chk2.checked == true do
(
for j in $.pos.controller.Y_Position.controller.keys do j.value = j.value + (random Param2.value Param1.value)
)

if chk3.checked == true do
(
for k in $.pos.controller.Z_Position.controller.keys do k.value = k.value + (random Param2.value Param1.value)
)

)


)

createDialog RandomPosRollout style:#(#style_border,#style_resizing,#style_toolwindow,#style_sysmenu)
)

Arno
arno3d.blogspot.com

magicm
06-09-2009, 01:53 PM
To randomise keys value I use this command :
for i in $.pos.controller.X_Position.controller.keys do i.value = i.value + (random -1 1)

But how can I randomise only selected keys ?
Key values have a .selected property (boolean), so you can use the following to iterate through selected keys only:
for i in $.pos.controller.X_Position.controller.keys where i.selected do i.value = i.value + (random -1 1)
Martijn

arno3d
06-09-2009, 02:13 PM
dank je wel

Arno
arno3d.blogspot.com

CGTalk Moderation
06-09-2009, 02:13 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.