.NET

Reply
Mentor
256 Posts
4 Kudos
Registered: ‎04-15-2011
Post 1 of 4

Transaction not needed?

177 Views, 3 Replies
05-20-2013 10:59 AM

Just curious about this. Why would the following code not require a transaction?

Essentially filtering and erasing objects.

 

            Dim psr As PromptSelectionResult = ed.SelectAll(filter)
            If psr.Status = PromptStatus.OK Then
                Dim idarray As ObjectId() = psr.Value.GetObjectIds()
                For Each ObjID In idarray
                    Dim Ent As Entity = ObjID.GetObject(OpenMode.ForWrite)
                    If TypeOf Ent Is Polyline Then
                        Ent.Erase()
                    End If
                Next
            End If

 

 

Valued Mentor
370 Posts
175 Kudos
Registered: ‎05-06-2012
Post 2 of 4

Re: Transaction not needed?

05-20-2013 02:19 PM in reply to: SRSDS

SRSDS wrote:

Just curious about this. Why would the following code not require a transaction?

Essentially filtering and erasing objects.

 

            Dim psr As PromptSelectionResult = ed.SelectAll(filter)
            If psr.Status = PromptStatus.OK Then
                Dim idarray As ObjectId() = psr.Value.GetObjectIds()
                For Each ObjID In idarray
                    Dim Ent As Entity = ObjID.GetObject(OpenMode.ForWrite)
                    If TypeOf Ent Is Polyline Then
                        Ent.Erase()
                    End If
                Next
            End If

 

 


The code does require a transaction. If it doesn't fail, it is because there is an active transaction in the document you're running it in.

 

The ObjectId.GetObject() method simply calls the GetObject() method of the active Transaction returned by the TransactionManager's TopTransaction property, and if there is no active transaction, it will fail.

*Expert Elite*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 3 of 4

Re: Transaction not needed?

05-20-2013 02:21 PM in reply to: SRSDS
Take a look at this page for more
http://spiderinnet1.typepad.com/blog/2012/04/open-direct-or-use-transaction-to-getobject-in-autocad-...
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
256 Posts
4 Kudos
Registered: ‎04-15-2011
Post 4 of 4

Re: Transaction not needed?

05-22-2013 04:11 AM in reply to: Hallex

Thankyou both. I did have an open transaction in a parent routine. I didn't realise that it was being used.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!