Below is some code snippes I'm working with, it's for the python arx wrappers I'm working on and unless I sort this out in the best possible fashion it will be the weak link in the chain!
When passing pointers back and forth with Python, you wrap your pointer in a CPyObject (basically a container for a void*) in this fashion -
// create the new line to pass back to python:
AcGePoint3d *p1 = new AcGePoint3d(x1, y1, z1);
AcGePoint3d *p2 = new AcGePoint3d(x2, y2, z2);
AcDbLine* newline = new AcDbLine(*p1, *p2);
return PyCObject_FromVoidPtr(newline, del_ent);
where 'del_ent' is a function ptr to a delete function for cleanup.
With that, Python has a pointer to the new db entity and can do what it needs to do with it, however, once you return back to the host app Python needs to do its cleanup, this is what I have so far, it works but I'm not happy with it -
static void del_ent(void* ptr)
{
/* just return and python will be happy, again, we need
to be careful with this as we could easily create a memory leak! */
AcDbEntity* e = (AcDbEntity*)ptr;
//e->upgradeOpen();
if(e->blockId() == AcDbObjectId::kNull) // it's not a db resident, we can delete it.
delete ptr;
//e->close();
return;
}
the problem is the doc's say you're not supposed to 'access' the pointer if it's not open, would using e->BlockId() without the entity being open be breaking the rules?? (it seems to work...)
Is there a better way to check if an entity/object belongs to a db without opening it?
thanks.
Mick.