.NET

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

When do I need to open a Transaction?

209 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 (197 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: 247
Registered: ‎04-15-2011
Message 3 of 3 (159 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.

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.