Notifications
Clear all

[Closed] New to maxscripting need help

here is a small script I wrote and it works however when I have no object selected I don’t get the message “Select at least one object!” instead I get an error message “no map function for undefined” Do you have ay suggestions? What else can I add to my code to make it a little more improved
Thanks.

rollout test “Random Displace” width:166 height:184
(
spinner xnpo “Max Dis:” pos:[64,26] width:86 height:16 range:[0,9999,0] type:#float scale:0.001 fieldwidth:40
spinner ynpo “Max Dis:” pos:[64,56] width:86 height:16 range:[0,9999,0] type:#float scale:0.001 fieldwidth:40
spinner znpo “Max Dis:” pos:[64,86] width:86 height:16 range:[0,9999,0] type:#float scale:0.001 fieldwidth:40
button btn1 “Randomize Position” pos:[20,120] width:134 height:29

on btn1 pressed  do
for obj in $ do 
    (
        if (selection.count > 0) then 
    (
    randXpos = random -xnpo.value xnpo.value 
    randYpos = random -ynpo.value ynpo.value 
    randZpos = random -znpo.value znpo.value 
    move obj [randXpos,randYpos,randZpos]     
    )
    
    else
    (
    messagebox "Select at least one object!"
    )
        
    )
1 Reply

You where getting the error becuse of this line for obj in $ do. If there is no selection here you get the error. so it never moved on to the next lins of code. Give this a try.


(
rollout test "Random Displace" width:166 height:184
(
spinner xnpo "Max Dis:" pos:[64,26] width:86 height:16 range:[0,9999,0] type:#float scale:0.001 fieldwidth:40
spinner ynpo "Max Dis:" pos:[64,56] width:86 height:16 range:[0,9999,0] type:#float scale:0.001 fieldwidth:40
spinner znpo "Max Dis:" pos:[64,86] width:86 height:16 range:[0,9999,0] type:#float scale:0.001 fieldwidth:40
button btn1 "Randomize Position" pos:[20,120] width:134 height:29

on btn1 pressed do
(
if $ == undefined then
(
 messagebox "Select at least one object!"
) 
else
(
for obj in $ do 
 (
 randXpos = random -xnpo.value xnpo.value 
 randYpos = random -ynpo.value ynpo.value 
 randZpos = random -znpo.value znpo.value 
 move obj [randXpos,randYpos,randZpos] 
 )
)
)
)
testFLOAT = newRolloutFloater "Random Displace" 200 210
addRollout test  testFLOAT
)