RhinoScript – Assign material id

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)

http://4.rhino3d.com/5/rhinoscript/object_methods/objectmaterialindex.htm