Script to change block geometry attributes to by parent

Hello,

May i ask for a favour. A script which would go inside block definitions of selected block instances and set all geometry to by parent (color, linetype, … everything) + it would select all curves inside block and asign pipe shader with defined radius and flat ending).

I hope it is few lines of code, but i cant do that.

Thank you

Hi @ivan.galik,

This might be a good starting point:

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 modified:
                sc.doc.Objects.ModifyAttributes(rh_obj, attributes, False)
    
    sc.doc.Views.Redraw()

if __name__ == "__main__":
    test_byparent()

test_byparent.py (1.8 KB)

– Dale

2 Likes

hi,

problem is it asks for definition name instad of selecting block instances. i have got around 500 block definitions and thousands of instances in file

Hi @ivan.galik,

I’m confused. Instance references don’t have any geometry. So why do you want to select them?

– dale

Just to say which definitions. 5000 instances can only be 200 definitions but its the most convenient way how to select definitions in model space via selecting instances.

@dale Hello, is it even possible to set mesh modification on curve (pipe) via scripting? I have got myriad of definitions where i need to set this + every property by parent.

its 3896 instances
235 definitions

-in all of these i have to set pipe modification (so that lines are visible from side otherwise plain curves are not displayed, should be as a point from side but it is a known bug)
-in all of these i need to set all properties by parent

Not that I can see. For blocks, you might consider using BlockEdit, so you can access the curves, and then script the _-Properties _CurvePiping option.

– Dale

Ivan, Are you aware of T-Rex?

https://code-structures.com/T_Rex_Manual/Manual%20for%20T-Rex.html

1 Like

yes i am but i had to go for my own solutions to be more flexible to cover very special cases

cousin helped me to modify it so that you can paste more block names at once. separator between names is ;

test_byparent (1).py (2.1 KB)

1 Like

it works like charm.

little trick i got block names from gh using elefront blocknames and used this site to convert it into delimited list Online Comma Separator - Convert List to CSV (Column to Comma)