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.
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.
or use the query() function:
msp = dxf.modelspace()
for circle in msp.query('CIRCLE'):
msp.delete_entity(circle)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.