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

Insert Block with Active Transaction

5 REPLIES 5
Reply
Message 1 of 6
absStructural
574 Views, 5 Replies

Insert Block with Active Transaction

Is there any way to insert a block when there is an active transaction?  I've seen examples of inserting blocks similar to http://forums.autodesk.com/t5/NET/How-to-insert-blockreference-not-in-drawing/m-p/1370564 - but if I use an existing open transaction (rather than commiting and starting a new transaction), I receive an eWasOpenForWrite error when calling doc.Database.Insert.  Ultimately, I would like to be able to pass an active transaction as a parameter to the function.

5 REPLIES 5
Message 2 of 6
caddzone
in reply to: absStructural

I don't think there's any way to do that without ending the transaction.

 



AcadXTabs for AutoCAD
Supporting AutoCAD 2000-2011


Message 3 of 6
fieldguy
in reply to: absStructural

You can pass a transaction like this:

 

Imports acaddbs = Autodesk.AutoCAD.DatabaseServices

 

Public Class Commands

Public Shared Sub quickScan()
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim db As acaddbs.Database = doc.Database
Using mytx As acaddbs.Transaction = db.TransactionManager.StartTransaction
           'Open the Block table for read
           Dim acBlkTbl As acaddbs.BlockTable
           acBlkTbl = mytx.GetObject(db.BlockTableId, acaddbs.OpenMode.ForRead)
           'Open the Block table record Modelspace for read
           Dim acBlkTblRec As acaddbs.BlockTableRecord
           acBlkTblRec = mytx.GetObject(acBlkTbl(acaddbs.BlockTableRecord.ModelSpace), _
                  acaddbs.OpenMode.ForRead)
           For Each objid As acaddbs.ObjectId In acBlkTblRec

                 Using ent As acaddbs.Entity = DirectCast(mytx.GetObject(objid, acaddbs.OpenMode.ForRead),    acaddbs.Entity)
                        dim myentdata as string = entData(ent, mytx)
                  End Using
              Next
        End Using 
     End Sub

 

     Public Shared Function entData(ByRef myent As acaddbs.Entity, ByRef mytr As acaddbs.Transaction) as string
         'return data about entity
     End Sub 'entData
  
End Class

 

I have not tried making any database changes with this - it might not work.   

Message 4 of 6
absStructural
in reply to: fieldguy

I understand the concept of passing a transaction as a parameter - in fact, I do it quite often in situations where opening and closing transactions would end up being slow.  The problem lies in adding a block to the drawing with an active transaction.  I've tried quite a few things - including trying to clone objects from the source database into a new BlockTableRecord in the destination database - but so far everything I've tried raises some error (eWasOpenForWrite for example).

Message 5 of 6
mohnston
in reply to: absStructural

That doesn't sound safe anyway.

Who knows what's going on in that transaction!

 

CAD Programming Solutions
Message 6 of 6
caddzone
in reply to: mohnston

No one can tell you much without seeing some code.

 

For example, what objects are open for write when you call Insert()?

 

The BlockTable?  Something else? 

 



AcadXTabs for AutoCAD
Supporting AutoCAD 2000-2011


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