web analytics
VIOLENT  VOLUMES

Rhinoscript – select random objects

'---------------------------------------------------------
'
'	Select random objects by percentage from selection
'	2012.06.02 Chris Daniel Kim
'
'---------------------------------------------------------
arrObjects = Rhino.GetObjects("Pick objects")
dblPercentage = Rhino.GetReal("Set percentage", 50, 0,100)

NumItems = int(dblPercentage*UBound(arrObjects)/100)
Rhino.Print NumItems & " elements will stay."

arrObjectsCopy = arrObjects

Dim i,j,tmp

Randomize 'Shuffle
For i = 1 To UBound(arrObjects) - 1
	' Pick a random element.
	j = Int((UBound(arrObjects) - i + 1) * Rnd + i)
	' Swap.
	tmp = arrObjectsCopy(i)
	arrObjectsCopy(i) = arrObjectsCopy(j)
	arrObjectsCopy(j) = tmp
Next

'Cut the tail
Redim Preserve arrObjectsCopy(NumItems)

Rhino.SelectObjects (arrObjectsCopy)

Categorised as: Generative design


Leave a Reply

Your email address will not be published. Required fields are marked *

Connect with Facebook

* Copy This Password *

* Type Or Paste Password Here *