Reputation: 53
I would like to delete every Circle entities form a DXF file. I'm using ezdxf, it seems to be a good tool for that kind of work.
I used ezdxf doc to write my code but I get an error from Python :
AttributeError: 'str' objet has no attribute 'destroy'
I don't understand why. I used this doc : http://pythonhosted.org/ezdxf/layouts.html#delete-entities
Here's my code :
import dxfgrabber
import ezdxf
dwg = dxfgrabber.readfile("test.dxf")
print(dwg)
c = []
center_points = [entity.center for entity in dwg.entities if entity.dxftype == 'CIRCLE']
dxf = ezdxf.readfile("test.dxf")
modelspace = dxf.modelspace()
for point in center_points:
modelspace.add_point(point)
c.append(point)
modelspace.delete_entity('CIRCLE')
dxf.save()
print(c)
Thanks.
Upvotes: 1
Views: 1660
Reputation: 2239
dxf.entities
contains the entities of the modelspace and the active paperspace:
msp = dxf.modelspace()
for circle in msp.query('CIRCLE'):
msp.delete_entity(circle)
Warning:
Do not delete entities from a container while iterating over it - the query()
function creates a temporary container, so deleting the entities from the modelspace is safe.
Upvotes: 3
Reputation: 53
I have succeeded. I post my code :
entities = dxf.entities
for e in entities:
if e.dxftype() == 'CIRCLE':
modelspace.delete_entity(e)
Instead of :
modelspace.delete_entity('CIRCLE')
I think it may have a better way to do it but it's working.
Upvotes: 2