Modifying object properties efficiently

Hi,
I am trying to change the object properties like Layer, Display Color, etc. but I want to keep some properties stay same. So, I cannot use MatchObjectProperties Method because it will change all the properties of the objects.

Seemingly, the only option I have now is to loop through each object and change each property using ObjectLayer, ObjectLinetype, etc. But, this option is too slow for looping thousands of objects I have in my drawings. Is there any other workaround? Or that part must stick to non-script way?

Thank you,
MHK

Most of these are object attributes, so you can modify them all at once:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

obj_ids=rs.GetObjects()

#get constants
layer_index=sc.doc.Layers.Find("Layer 01",False)
color=rs.coercecolor([255,0,0])
by_object=Rhino.DocObjects.ObjectColorSource.ColorFromObject

for obj_id in obj_ids:
    rhobj=rs.coercerhinoobject(obj_id)
    rhobj.Attributes.LayerIndex=layer_index
    rhobj.Attributes.ColorSource=by_object
    rhobj.Attributes.ObjectColor=color
    #etc. for all desired attributes
    rhobj.CommitChanges()
sc.doc.Views.Redraw()

Don’t know how much faster that is…

1 Like

It works!!

I tried such method previously, but it was taking too much time. I thought the reason was because it was loading full object instance in each loop; not the guid as in ModifyAttributes method.

Now, I looked at my code again; I was looping Views.Redraw() for every object!! Now I put it outside the loop and it runs fast indeed.

Thanks for your reply.