Random Selection Script

Random Selection Script

Anonymous
Not applicable
530 Views
5 Replies
Message 1 of 6

Random Selection Script

Anonymous
Not applicable
Hi guys,

I wonder if anyone can help me. I have a script that someone on here put together a couple of years back.

clearSelection ()
for i = 11 to 5698 by 3 do
(
obj = execute ("$" + "Circle_" + i as string)
if obj != undefined do
(selectMore obj)
)
s=selection


The idea of the script is to select every 3rd object within a selection (named "circle_xx" in this example). I use this when I have a selection of, for example, 10000 objects which I need to split into a number of separate groups to "Align & Clone" another object to.

Although this works fine for most duties I need something different this time. I need a more "random" selection. Can this script be revised to make the selection more random...?

The attached screen dump shows an example of the selection which clearly shows distinct rows.

Edit: Looks like the attatchement won't upload from work... I'll try from home later.

Any help would be much appreciated.

Regards

Roly
0 Likes
531 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

for o in $Circle* where (random 1 3) == 3 do
selectMore o
0 Likes
Message 3 of 6

Anonymous
Not applicable
$Circle should have read (dollar sign)Circle. The forum software stomped it.
0 Likes
Message 4 of 6

Steve_Curley
Mentor
Mentor

(
clearSelection()

for i = 1 to 10 do -- we want 10 circles selected
(
local done = false
do
(
n = stringstream ""
r = random 1 100 -- pick any of the 100 available circles
format "$Circle_%" (formattedPrint r format:"2.2d") to:n
obj = execute (n as string)
if (obj != undefined) then -- only continue if a valid object
(
if (not obj.isSelected) then -- only continue if the object is not already selected
(
selectMore obj
done = true -- finished this one
)
)
)
while (not done) -- end "do" loop, repeat until one is selected
) -- end "for" loop
)

Change the loop counter to the number you want to select
Change the random value(s) to suit however many there are to choose from
If you were looping from 11 to avoid the problem of "Circle_01" etc, the above code takes care of that for you. Loop from 1 to however many you want (easier to read...).

randomselection.ms.zip


Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 5 of 6

Anonymous
Not applicable
I noticed that with the $ code when I posted the original message... perhaps that needs reporting.

Stokes... you're a star, this works fine... I really need to learn this MaxScript stuff and spend less time working :)
0 Likes
Message 6 of 6

Anonymous
Not applicable

(
clearSelection()

for i = 1 to 10 do -- we want 10 circles selected
(
local done = false
do
(
n = stringstream ""
r = random 1 100 -- pick any of the 100 available circles
format "$Circle_%" (formattedPrint r format:"2.2d") to:n
obj = execute (n as string)
if (obj != undefined) then -- only continue if a valid object
(
if (not obj.isSelected) then -- only continue if the object is not already selected
(
selectMore obj
done = true -- finished this one
)
)
)
while (not done) -- end "do" loop, repeat until one is selected
) -- end "for" loop
)

Change the loop counter to the number you want to select
Change the random value(s) to suit however many there are to choose from
If you were looping from 11 to avoid the problem of "Circle_01" etc, the above code takes care of that for you. Loop from 1 to however many you want (easier to read...).


Change the loop counter to the number you want to select
Change the random value(s) to suit however many there are to choose from
If you were looping from 11 to avoid the problem of "Circle_01" etc, the above code takes care of that for you. Loop from 1 to however many you want (easier to read...).


Steve, this looks great too. I've done what I need to do now thanks to Stokes' tip but I'm sure this will useful for future use. Thanks very much!!!
0 Likes