I really need a script for changing the layer of all objects in a block.
For example;
There are some blocks with lots of objects and blocks in the file. I want to move all of them into a specific layer with displaycolor=BYLAYER, printcolor=BYLAYER… Now, i have to activate block, select objects and change all properties individually. If there any other blocks inside this block, i repeat above.
This sample script converts all of the properties of objects referenced by an instance definition to “By Parent”. Might be a good starting point for you.
import Rhino
import scriptcontext as sc
def test_byparent():
rc, idef_name = Rhino.Input.RhinoGet.GetString("Instance definition name", False, "")
if rc != Rhino.Commands.Result.Success or not idef_name:
return
idef_name = idef_name.strip()
if not idef_name:
return
idef = sc.doc.InstanceDefinitions.Find(idef_name, True)
if not idef:
print("Instance definition \"{0}\" not found.".format(idef_name))
for i in range(0, idef.ObjectCount):
rh_obj = idef.Object(i)
if rh_obj:
attributes = rh_obj.Attributes.Duplicate()
modified = False
if attributes.ColorSource != Rhino.DocObjects.ObjectColorSource.ColorFromParent:
attributes.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromParent
modified = True
if attributes.LinetypeSource != Rhino.DocObjects.ObjectLinetypeSource.LinetypeFromParent:
attributes.LinetypeSource = Rhino.DocObjects.ObjectLinetypeSource.LinetypeFromParent
modified = True
if attributes.PlotColorSource != Rhino.DocObjects.ObjectPlotColorSource.PlotColorFromParent:
attributes.PlotColorSource = Rhino.DocObjects.ObjectPlotColorSource.PlotColorFromParent
modified = True
if attributes.PlotWeightSource != Rhino.DocObjects.ObjectPlotWeightSource.PlotWeightFromParent:
attributes.PlotWeightSource = Rhino.DocObjects.ObjectPlotWeightSource.PlotWeightFromParent
modified = True
if attributes.MaterialSource != Rhino.DocObjects.ObjectMaterialSource.MaterialFromParent:
attributes.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromParent
modified = True
if modified:
sc.doc.Objects.ModifyAttributes(rh_obj, attributes, False)
sc.doc.Views.Redraw()
if __name__ == "__main__":
test_byparent()