Forgot password?

Create an account!

Forum

« back

RhinoScript – Assign material id

Messages

Please log in to write a message.

  • 1. p3tr4s (Dec 19, 2014 15.00):

    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)

Recommend

Why are these buttons gray?