undo issue using ->erase() to delete an entity

undo issue using ->erase() to delete an entity

ShricharanaB
Advocate Advocate
703 Views
2 Replies
Message 1 of 3

undo issue using ->erase() to delete an entity

ShricharanaB
Advocate
Advocate

Hi, 

I'm just trying to create some different commands to learn objectARX.

 

Here, I found a function  using ssget and ->erase() to delete the selected entities. It does delete the the entities. But After I run this command and delete the entities if I undo, the deleted entities remain deleted while everything else I did will undo. 

 

Ex:-  I create a rectangle > create a circle, move the circle and call the delete function and select the rectangle and delete. - the rectangle is deleted.

Then I undo, message I get in commandline -> "_U FDEL" - but the rectangle is still deleted. (fdel being the command name)

Undo again, message I get -> "_U MOVE" - but the rectangle is still deleted.

So the rectangle is gone permanently. 

How do I fix this? 

Below is the function

void deleteEntity()
{
	ads_name ssname;
	acedSSGet(NULL, NULL, NULL, NULL, ssname);
	Adesk::Int32 number = 0;
	if ((acedSSLength(ssname, &number ) != RTNORM) || (number == 0))
	{
		acedSSFree ( ssname );
	}
	ads_name ent;
	AcDbObjectId id = AcDbObjectId::kNull;

	for (long i = 0; i < number; i++)
	{
		acedSSName(ssname, i, ent) != RTNORM;
		acdbGetObjectId(id, ent);
		AcDbEntity * pEnt = NULL;
		acdbOpenAcDbEntity(pEnt, id, AcDb::kForWrite);
		pEnt->erase ();
	}
	acedSSFree(ssname);
	ads_regen();
}

Thanks in advance for any help.

0 Likes
Accepted solutions (1)
704 Views
2 Replies
Replies (2)
Message 2 of 3

daniel_cadext
Advisor
Advisor
Accepted solution

After calling pEnt->erase (); make sure you call pEnt->close(); things may get wonky if it's left open for write

 

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
Message 3 of 3

ShricharanaB
Advocate
Advocate

@daniel_cadext That worked!

 

Thank you!

0 Likes