ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help! derive from AcDbentiy, but crash when moving\saving\arxunload

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
172 Views, 2 Replies

Help! derive from AcDbentiy, but crash when moving\saving\arxunload

I creat a castum object ,deriving from AcDbEntiy ,display normal,but crsah when moving....
-------------------------------------------------------------
class myENT: public AcDbEntity
{
public:
ACRX_DECLARE_MEMBERS(myENT);
myENT();
~myENT();
virtual Adesk::Boolean worldDraw(AcGiWorldDraw *);
Acad::ErrorStatus transformBy(const AcGeMatrix3d &);
void list() const;
void set_pEntity(AcDbEntity *);
private:
AcDbEntity* m_pEnt;
};
---------------------------------------------------------
void myENT::set_pEntity(AcDbEntity* pEnt)
{
assertReadEnabled();
//m_pEnt = AcDbEntity::cast(pEnt);
m_pEnt = (AcDbEntity*)(pEnt->clone());
}
------------------------------------------------------------
void addmyENT(AcDbEntity *pEnt)
{
Acad::ErrorStatus es;
AcDbBlockTable *pBlockTable;
es = acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable, AcDb::kForRead);
if (es != Acad::eOk)
return;

AcDbBlockTableRecord *pBlock;
es = pBlockTable->getAt(ACDB_MODEL_SPACE, pBlock,
AcDb::kForWrite);
if (es != Acad::eOk)
return;

AcDbObjectId objId;
myENT *pNewObj = new myENT;

pNewObj->set_pEntity(pEnt);

es = pBlock->appendAcDbEntity(objId, pNewObj);
if (es != Acad::eOk) {
delete pNewObj;
return;
}

es = pBlock->close();
if (es != Acad::eOk)
acrx_abort("\nUnable to close block table record");

es = pBlockTable->close();
if (es != Acad::eOk)
acrx_abort("\nUnable to close block table");

es = pNewObj->close();
if (es != Acad::eOk)
acrx_abort("\nUnable to close new entity");
}
--------------------------------------------------
void do_all()
{
ads_name sset;
int err = acedSSGet(NULL, NULL, NULL, NULL, sset);
if (err != RTNORM) {
return;
}
long length;
acedSSLength(sset, &length);
if(length == 0)
{
acedSSFree(sset);
return;
}
ads_name entName;
AcDbObjectId oId;
AcDbEntity* pEnt;
Acad::ErrorStatus es;
long rejected = 0;
for(long i=0; i {
acedSSName(sset, i, entName);
acdbGetObjectId(oId, entName);
es = acdbOpenAcDbEntity(pEnt, oId, AcDb::kForRead);
if(es != Acad::eOk)
{
acedSSFree(sset);
return;
}

//....
addSmartlockOTHER(pEnt);
pEnt->close();
}
acedSSFree(sset);
}
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

You must implement dwgIn and dwgOut fields.
When you move your entity, a copy is made, using the filing.
I guess m_pEnt is invalid in the copied entity.

/Matt



wrote in message news:5103430@discussion.autodesk.com...
I creat a castum object ,deriving from AcDbEntiy ,display normal,but crsah
when moving....
-------------------------------------------------------------
class myENT: public AcDbEntity
{
public:
ACRX_DECLARE_MEMBERS(myENT);
myENT();
~myENT();
virtual Adesk::Boolean worldDraw(AcGiWorldDraw *);
Acad::ErrorStatus transformBy(const AcGeMatrix3d &);
void list() const;
void set_pEntity(AcDbEntity *);
private:
AcDbEntity* m_pEnt;
};
---------------------------------------------------------
void myENT::set_pEntity(AcDbEntity* pEnt)
{
assertReadEnabled();
//m_pEnt = AcDbEntity::cast(pEnt);
m_pEnt = (AcDbEntity*)(pEnt->clone());
}
------------------------------------------------------------
void addmyENT(AcDbEntity *pEnt)
{
Acad::ErrorStatus es;
AcDbBlockTable *pBlockTable;
es = acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable, AcDb::kForRead);
if (es != Acad::eOk)
return;

AcDbBlockTableRecord *pBlock;
es = pBlockTable->getAt(ACDB_MODEL_SPACE, pBlock,
AcDb::kForWrite);
if (es != Acad::eOk)
return;

AcDbObjectId objId;
myENT *pNewObj = new myENT;

pNewObj->set_pEntity(pEnt);

es = pBlock->appendAcDbEntity(objId, pNewObj);
if (es != Acad::eOk) {
delete pNewObj;
return;
}

es = pBlock->close();
if (es != Acad::eOk)
acrx_abort("\nUnable to close block table record");

es = pBlockTable->close();
if (es != Acad::eOk)
acrx_abort("\nUnable to close block table");

es = pNewObj->close();
if (es != Acad::eOk)
acrx_abort("\nUnable to close new entity");
}
--------------------------------------------------
void do_all()
{
ads_name sset;
int err = acedSSGet(NULL, NULL, NULL, NULL, sset);
if (err != RTNORM) {
return;
}
long length;
acedSSLength(sset, &length);
if(length == 0)
{
acedSSFree(sset);
return;
}
ads_name entName;
AcDbObjectId oId;
AcDbEntity* pEnt;
Acad::ErrorStatus es;
long rejected = 0;
for(long i=0; i {
acedSSName(sset, i, entName);
acdbGetObjectId(oId, entName);
es = acdbOpenAcDbEntity(pEnt, oId, AcDb::kForRead);
if(es != Acad::eOk)
{
acedSSFree(sset);
return;
}

//....
addSmartlockOTHER(pEnt);
pEnt->close();
}
acedSSFree(sset);
}
Message 3 of 3
Anonymous
in reply to: Anonymous

Matt:
Thanks a lot!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost