.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Transaction not needed?

3 REPLIES 3
Reply
Message 1 of 4
SRSDS
505 Views, 3 Replies

Transaction not needed?

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

 

 

3 REPLIES 3
Message 2 of 4
DiningPhilosopher
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.

Message 3 of 4
Hallex
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
Message 4 of 4
SRSDS
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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost