Author Topic: Take me to your leader  (Read 7618 times)

0 Members and 1 Guest are viewing this topic.

Glenn R

  • Guest
Re: Take me to your leader
« Reply #15 on: June 30, 2008, 05:21:21 PM »
...as this would probably mean the MText content is null...

sinc

  • Guest
Re: Take me to your leader
« Reply #16 on: June 30, 2008, 05:36:26 PM »
OK, guess I'll have to dig into it more.

That looks identical to what I've tried, but I only get crashes.

Oh, I should probably add that I'm attempting to change the item from the Database.ObjectAppended event handler.  Well, not exactly there, because attempting to edit it there would cause a crash.  But I store the ObjectId of the newly-created MLeader in my event handler for Database.ObjectAppended, and then I try to access it in the DocumentManager.DocumentLockModeWillChange event handler.  When I try to do that, the ObjectId is 0, and the UpgradeOpen fails.

Glenn R

  • Guest
Re: Take me to your leader
« Reply #17 on: June 30, 2008, 05:47:39 PM »
Oh, I should probably add that I'm attempting to change the item from the Database.ObjectAppended event handler.  Well, not exactly there, because attempting to edit it there would cause a crash.  But I store the ObjectId of the newly-created MLeader in my event handler for Database.ObjectAppended, and then I try to access it in the DocumentManager.DocumentLockModeWillChange event handler.  When I try to do that, the ObjectId is 0, and the UpgradeOpen fails.

I'm not surprised one little bit. Also, you're only just mentioning this? This is why I asked for sample code.
None of that will work as AutoCAD is 'doing stuff' and has it open. Also, don't even try modifying objects in DocLockModWillChange as you're just asking for trouble.

Redesign your attack.

Glenn R

  • Guest
Re: Take me to your leader
« Reply #18 on: June 30, 2008, 06:00:00 PM »
Sorry - I made an incorrect statement when I posted that ObjectId = 0 is null.

Before I consulted the docs, I was under the impression that the MText property returned an ObjectId - this is not the case. It returns a pointer to the clone and in C based languages, a null pointer can be initialised to 0 (or NULL in the MS implementations which is an alias for 0).

sinc

  • Guest
Re: Take me to your leader
« Reply #19 on: June 30, 2008, 09:39:59 PM »
Well, as you might imagine, it would not be easy to extract the code in question, especially into a self-contained snippet that someone could actually run.  It's embedded in a rather large application.

But yeah, I understand that code samples make it easier to detect issues.

So where is the approved place of modifying an object that has just been appended to the database?  I put it where I did because I was copying either a post by Tony Tanzillo or Kean, I can't remember which.  But I may have mis-applied it - I'll have to look again for the post that caused me to do what I did, and see if I misread it.

But to get back to the important point, where is the approved place to modify a newly-appended database entity?

sinc

  • Guest
Re: Take me to your leader
« Reply #20 on: June 30, 2008, 10:07:18 PM »
Is Document.CommandEnded a good place to modify database entities?

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Take me to your leader
« Reply #21 on: June 30, 2008, 10:20:57 PM »
ent.upgrade open maybe??
I'm sure in ARX until you close the object even after adding it to the db you can edit it, can't quite remember though...
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

sinc

  • Guest
Re: Take me to your leader
« Reply #22 on: July 01, 2008, 02:27:54 AM »
Is Document.CommandEnded a good place to modify database entities?

Well, I checked in CommandEnded, and the ObjectId is still 0 there, so that doesn't work.

But I also saw a post by Tony T that said doing things in CommandEnded can cause problems with Undo/Redo.  So that doesn't seem to be a good idea in any case.

I found the sample code that caused me to put it in DocumentLockModeWillChange in the first place, and sure enough, it came from Kean Walmsley's column, where he uses the technique on blocks:

http://through-the-interface.typepad.com/through_the_interface/files/auto-bubble-creation-part4.cs

Glenn R

  • Guest
Re: Take me to your leader
« Reply #23 on: July 01, 2008, 05:24:30 AM »
ent.upgrade open maybe??
I'm sure in ARX until you close the object even after adding it to the db you can edit it, can't quite remember though...

Acad still has it open for write during the event Mick. Many may read, but 'there can be only one' for write.
Think of a polyline.

The poly header gets added and ObjectAppended fires.
Next vertex is added and ObjectAppended fires.

At this stage, you do not have a complete object to work with.

Next vertex is added and ObjectAppended fires.
Command is finished and SEQEND is added to poly and entity closed.

The best way to see this is to fire up ArxDbg, enable it events for the dbase and start adding things.
You will be surprised as to the order of event invocation.

Glenn R

  • Guest
Re: Take me to your leader
« Reply #24 on: July 01, 2008, 04:02:17 PM »
Also, WRT my post quoting the docs, you will need to destroy the MText object.

Glenn R

  • Guest
Re: Take me to your leader
« Reply #25 on: July 02, 2008, 02:30:57 PM »
...as it's a clone and not dbase resident. I suspect that if you didn't do this, you would end up in memory-leak-land.