.NET

Reply
Mentor
SRSDS
Posts: 250
Registered: ‎04-15-2011
Message 1 of 4 (170 Views)

Transaction not needed?

170 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
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 2 of 4 (152 Views)

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*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 4 (148 Views)

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
SRSDS
Posts: 250
Registered: ‎04-15-2011
Message 4 of 4 (113 Views)

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 Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!