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

how auto-modify the entity newly appended to db?

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
jzq740176597
743 Views, 8 Replies

how auto-modify the entity newly appended to db?

like the title mentioned above,

If i want to auto-modify the entity newly appended to db, i.e for newly appended entity ,I want to change it's colorIndex to 0;

 

or according to the type of the entity,for AcDbline I change the length,for circle ,I change the radius.

 

I know for catching every entity appended Msg I can use the AcDbDatabaseReactor subclass.

and override    

virtual void objectAppended(const AcDbDatabase* dwg,
        const AcDbObject* dbObj);

 But the in that callback function, dbObj is read-only.

So can you help me ??

8 REPLIES 8
Message 2 of 9
maisoui
in reply to: jzq740176597

Hi,

 

The following code will help you:

 

if(dbObj->isWriteEnabled() || dbObj->upgradeOpen() == Acad::eOk)
{
   //your code here...
}

 

Regards,

Jonathan

 

--
Jonathan
Message 3 of 9
jzq740176597
in reply to: maisoui

thank you first!
but it's doesn't work!
virtual void objectAppended(const AcDbDatabase* dwg,
        const AcDbObject* dbObj);

 

dbObj is const AcDbObject*.

 

in objectAppended function, dbObj->isWriteEnabled() always return false and dbObj->upgradeOpen() is used on no-const object .

 

So const AcDbObject* dbObj must cast to no-const one. but this fill abort the autoCAD.

Message 4 of 9
maisoui
in reply to: jzq740176597

Yes, you're right. I tried something not very clean (i.e. C cast):

 

...::objectAppended(...)
{
   if(dbObj->isKindOf(AcDbPolyline::desc()))
      myFunction((AcDbPolyline *)dbObj);
}

 

Another approach is to store the object ids in objectAppended and treat the list of your ids when commandEnded.

 

--
Jonathan
Message 5 of 9
maisoui
in reply to: maisoui

Additional information: it works with AcDbObject::cast method (like this: AcDbPolyline::cast(dbObj))

--
Jonathan
Message 6 of 9
owenwengerd
in reply to: jzq740176597

You have to choose a later context to perform your modifications. The typical pattern is to use the reactor to gather and store the object ids of objects you're interested in, then perform your processing on the objects later, perhaps in a different reactor.

--
Owen Wengerd
ManuSoft
Message 7 of 9
jzq740176597
in reply to: maisoui

hi maisoui !
if(dbObj->isKindOf(AcDbPolyline::desc()))
myFunction((AcDbPolyline *)dbObj); //will error

AutoCAD: internal error : dbobj is not open for write!

Take owenwengerd answer:
[You have to choose a later context to perform your modifications. The typical pattern is to use the reactor to gather and store the object ids of objects you're interested in, then perform your processing on the objects later, perhaps in a different reactor]

Thanks you any way!
Message 8 of 9
jzq740176597
in reply to: owenwengerd

THANKS owenwengerd !
I got it and accept as solution!
Message 9 of 9
cadc
in reply to: owenwengerd


@owenwengerd wrote:

You have to choose a later context to perform your modifications. The typical pattern is to use the reactor to gather and store the object ids of objects you're interested in, then perform your processing on the objects later, perhaps in a different reactor.



I guess your answer is right, but in *what another reactor* to to processing on the objects later? if I want to modify the newly appended entity at once.

Tags (3)

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

Post to forums  

”Boost