Grasshopper

algorithmic modeling for Rhino

Hi,

How can assign material id to selected objects?

Below I have the script that randomly selects objects.


For example, I select objects and want to assign material id number 9 for all of them.

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)



Views: 423

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service