Hi, it seems Python’s GC runs FIFO, which is causing a slight problem with my AutoCAD wrappers
- Database is a collection of dbobjects that may be opened for read or write
- Database std::shared_ptr that is deleted in the dtor
- Dbobject is a std::shared_ptr that calls ptr->close() in the dtor
- Python GC’s the database, first, invalidating all the pointers first, so AutoCAD crashes when ptr->close() is called.
IMHO, GC should work like a stack (FILO), but I’m really not that familiar with Python.
Is there an elegant solution besides making the user create a new function just for a scope?
sample
import traceback
from pyrx import Db, Ed, Ge, Ap, Rx, Gs
@Ap.Command()
def doit():
try:
longest = 0
for file in Ap.Application.listFilesInPath("E:\\temp", ".dwg"):
# read the file
sdb = Db.Database(False, True)
sdb.readDwgFile(file)
sdb.closeInput(True)
#opened for read
ms = sdb.modelSpace(Db.OpenMode.kForRead)
#opened for read
crvs = [
Db.Curve(id, Db.OpenMode.kForRead) for id in ms.objectIds(Db.Curve.desc())
]
for crv in crvs:
longest = max(longest, crv.getDistAtParam(crv.getEndParam()))
# Database is deleted first, kludge
dummy = sdb #ugggg
print(longest)
except Exception as err:
traceback.print_exception(err)