DeleteLinesNested In blocks

Hi people.
I was just trying to batch delete lines that were left inside blocks and nested. Couldn’t do it with a macro, looks like block editor creates kind of a gap in the sequence.
I turned to scripting, found the curves but still, no success in deleting them.
Any ideas?

Here’s my code :

import rhinoscriptsyntax as rs
import pprint as p

print "There are ",  rs.BlockCount(),  " blocks in this file."

for blockName in rs.BlockNames(False):
    myBlocks = rs.BlockObjects(blockName)
    for id in myBlocks:
        if rs.IsCurve(id):
            print "found a curve:"
            print id
            crvsList.append(id)
        else:
            print "not a curve"

crvsList = []

for crv in crvsList:
    rs.SelectObject(crv)
    rs.DeleteObject(crv)

Hi @cbecta1,

This script doesn’t do any error checking. But it should give you some ideas:

import Rhino
import scriptcontext as sc
import System

def RemoveCurvesFromInstanceDefinitions():
    
    for idef in sc.doc.InstanceDefinitions:
        rhino_objects = idef.GetObjects()
        geometry = System.Collections.Generic.List[Rhino.Geometry.GeometryBase]()
        attributes = System.Collections.Generic.List[Rhino.DocObjects.ObjectAttributes]()
        for rh_obj in rhino_objects:
            if rh_obj.ObjectType != Rhino.DocObjects.ObjectType.Curve:
                geometry.Add(rh_obj.Geometry)
                attributes.Add(rh_obj.Attributes)
            sc.doc.InstanceDefinitions.ModifyGeometry(idef.Index, geometry, attributes)
    sc.doc.Views.Redraw()
    
RemoveCurvesFromInstanceDefinitions()

– Dale

1 Like