.NET

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

Transaction not needed?

174 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 (156 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 (152 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: 256
Registered: ‎04-15-2011
Message 4 of 4 (117 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
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.