ObjectARX

Reply
Contributor
mihajlovic.milosh
Posts: 11
Registered: ‎11-07-2011
Message 1 of 12 (287 Views)
Accepted Solution

XData or something else?

287 Views, 11 Replies
04-10-2012 09:19 AM

 

 

I need to save some data for each block reference and then with reactors update block attributes using that saved data and geometric properties of that block. For instance, one block attribute contains X coordinate, prefix text, suffix text and coordinate precision. Each time the block is moved, the program needs to update X coordinate.

 

Sp, what should I use: xData or something else?

acdbEvaluateFields function can help you to update fields.

The problem was that you cannot call acdbEvaluateFields() when closing the object. I had to remember which object was edited in an editor reactor and then in commandEnded() funciton call acdbEvaluateFields().

*Expert Elite*
Alfred.NESWADBA
Posts: 9,608
Registered: ‎06-29-2007
Message 2 of 12 (284 Views)

Re: XData or something else?

04-10-2012 09:25 AM in reply to: mihajlovic.milosh

Hi,

 

>> Each time the block is moved, the program needs to update X coordinate.

I don't know what AutoCAD-version you are using, but why don't you use the built-in fields in attributes (>>>details<<<)? If you add a field into the attribute that grabs the insertion-X from your blockreference everything is done without any programming!

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Distinguished Mentor
owenwengerd
Posts: 686
Registered: ‎08-06-2002
Message 3 of 12 (282 Views)

Re: XData or something else?

04-10-2012 09:25 AM in reply to: mihajlovic.milosh

Unless you must support very old versions of AutoCAD, I would use a field and let AutoCAD do the work. Otherwise, xdata would be fine if your data is always very small. If there's a potential for using up all the xdata space, an extension dictionary would be the next choice.

--
Owen Wengerd
ManuSoft
Contributor
mihajlovic.milosh
Posts: 11
Registered: ‎11-07-2011
Message 4 of 12 (278 Views)

Re: XData or something else?

04-10-2012 09:42 AM in reply to: mihajlovic.milosh
Actually, I am using fields right now. But I don't know how to update fields from the reactor. When I try to regen from reactor acad crashes... Any thoughts?
Moderator
Alexander.Rivilis
Posts: 1,458
Registered: ‎04-09-2008
Message 5 of 12 (274 Views)

Re: XData or something else?

04-10-2012 10:18 AM in reply to: mihajlovic.milosh
acdbEvaluateFields function can help you to update fields.

Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Contributor
mihajlovic.milosh
Posts: 11
Registered: ‎11-07-2011
Message 6 of 12 (264 Views)

Re: XData or something else?

04-10-2012 03:52 PM in reply to: mihajlovic.milosh

Thank you.

But this doesn't work (it raises FATAL ERROR dialog in AutoCAD):

 

	void modified(const AcDbObject* dbObj) {
		AcDbObject *pBlkRef;
		ErrorStatus err = acdbOpenObject(pBlkRef, dbObj->objectId(), AcDb::kForWrite);
		if (err != eOk) {
			pBlkRef->close();
			return;
		}
		err = acdbEvaluateFields(dbObj->objectId(), AcDbField::kAutomatic);
		if (err != eOk) {
			pBlkRef->close();
			return;
		}
		pBlkRef->close();
	}

 

Contributor
mihajlovic.milosh
Posts: 11
Registered: ‎11-07-2011
Message 7 of 12 (255 Views)

Re: XData or something else?

04-10-2012 06:37 PM in reply to: mihajlovic.milosh

OK I realized what's the problem.

 

The reactor's modified() function is called when object->close() function is invoked. So acdbEvaluateFields() throws eWasNotified. But I need to call acdbEvaluateFields() from the modified() function. I also tried with objectClosed() method - the same story...

 

Does somebody have a clue how can I solve this? 

Moderator
Alexander.Rivilis
Posts: 1,458
Registered: ‎04-09-2008
Message 8 of 12 (252 Views)

Re: XData or something else?

04-10-2012 10:14 PM in reply to: mihajlovic.milosh

What about:

void modified(const AcDbObject* dbObj) 
{
   acdbEvaluateFields(dbObj->objectId(), AcDbField::kAutomatic);
}

?

IMHO. This is not the best place to call acdbEvaluateFields. I would prefer to use a command-reactor (for example, commandEnded). modified-reactor can collect AcDbObjectId of modified objects in order to call acdbEvaluateFields in command-reactor.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Contributor
mihajlovic.milosh
Posts: 11
Registered: ‎11-07-2011
Message 9 of 12 (228 Views)

Re: XData or something else?

04-17-2012 05:38 AM in reply to: Alexander.Rivilis

The problem was that you cannot call acdbEvaluateFields() when closing the object. I had to remember which object was edited in an editor reactor and then in commandEnded() funciton call acdbEvaluateFields().

Moderator
Alexander.Rivilis
Posts: 1,458
Registered: ‎04-09-2008
Message 10 of 12 (225 Views)

Re: XData or something else?

04-17-2012 05:58 AM in reply to: mihajlovic.milosh

mihajlovic.milosh wrote:

The problem was that you cannot call acdbEvaluateFields() when closing the object. I had to remember which object was edited in an editor reactor and then in commandEnded() funciton call acdbEvaluateFields().


Now OK?


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.