.NET

.NET

Reply
Mentor
SRSDS
Posts: 255
Registered: ‎04-15-2011
Message 1 of 3 (212 Views)
Accepted Solution

When do I need to open a Transaction?

212 Views, 2 Replies
12-14-2011 01:03 PM

Hi,

 

I often see examples of accessing objects without opening a transaction.

 

This has no reference to a transaction

Dim Ent As Entity = ObjID.GetObject(OpenMode.ForRead)

but when I try to use it in a reactor it jumps to the ObjectModified event and then not back to the continuing code. 

 

I have this in my CommandEnded event

           ElseIf e.GlobalCommandName = "EATTEDIT" Then
                'Check if DrawingNo changed
                Dim Ent As Entity = ObjID.GetObject(OpenMode.ForRead)
                Dim myXdata As Array = Ent.XData.AsArray
                If myXdata.GetValue(0).value = "TitleBlock" Then

 And don't understand why I need to open a transaction to see if it's a Titleblock

 

What's the difference between

Dim Ent As Entity = ObjID.GetObject(OpenMode.ForRead)

and

Dim Ent As Entity = trans.GetObject(ObjID, OpenMode.ForRead)

Hope someone can help.


SRSDS wrote:

What's the difference between

Dim Ent As Entity = ObjID.GetObject(OpenMode.ForRead)

and

Dim Ent As Entity = trans.GetObject(ObjID, OpenMode.ForRead)


Short answer, there isn't one.  You must have an active transaction to call GetObject.  Even when you call Objid.GetObject, the Top Level Transaction still handles the object, so if there is no active transaction it will fail.

*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 2 of 3 (200 Views)

Re: When do I need to open a Transaction?

12-14-2011 02:12 PM in reply to: SRSDS

SRSDS wrote:

What's the difference between

Dim Ent As Entity = ObjID.GetObject(OpenMode.ForRead)

and

Dim Ent As Entity = trans.GetObject(ObjID, OpenMode.ForRead)


Short answer, there isn't one.  You must have an active transaction to call GetObject.  Even when you call Objid.GetObject, the Top Level Transaction still handles the object, so if there is no active transaction it will fail.

Dave O.                                                                  Sig-Logos32.png
Mentor
SRSDS
Posts: 255
Registered: ‎04-15-2011
Message 3 of 3 (162 Views)

Re: When do I need to open a Transaction?

12-15-2011 08:49 AM in reply to: chiefbraincloud

Thanks Chief,

 It looks like I'm doing it right then.

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.