1

I am using the ezdxf package to postprocess DXF drawings. Then, I convert the DXF to a SVG.

During the postprocessing, I need to delete some INSERT entitities that lie outside the drawing area so that the converted SVG has the right dimensions. I am doing something like this :

def dxftype(entity):
   notHandled = []
   if entity.dxftype() in notHandled:
    return None
   else:
    return entity.dxftype()

def hasToBeDeleted(entity):
 """
 Some criteria for deleting an entity
 return a Boolean
 """

dwg = ezdxf.readfile("myDxfFile.dxf")
msp = dwg.modelspace()
group = msp.groupby(key=dxftype)

for entityType, entities in group.items():
 for e in entities:
  if hasToBedeleted(e):
   msp.delete_entity(e)

The problem is that then, when converting the entity is not deleted. In fact, if I do another loop of suppression right after this one, the loop still takes the action to delete the entity proving the entity has not really been removed from the modelspace.

What is the correct way to delete an entity from the modelspace in ezdxf then ? I am using version 0.9 at the moment and can't upgrade to a new version right now

FenryrMKIII
  • 1,068
  • 1
  • 13
  • 30

1 Answers1

0

I'm just starting with ezdxf and saw this:

https://ezdxf.mozman.at/docs/develop/entitydb.html

notibly the purge and trashcan. The trashcan mentions "when leaving context", so perhaps there is a way to use a with statement to facilitate removal of objects? Saving that, explicitly calling purge after your loop with delete_entity? The iterator documentation says it wouldn't return deleted items, but "nuke it from orbit, it's the only way to be sure" is a great motto.

Elton Clark
  • 146
  • 1
  • 10