Hello guys,
I've got a good amount of .NET code written for AutoCAD 2009 wherein methods return BlockReference objects.
These BlockReferences stayed valid & initialized after being returned. In BricsCAD however, the reference to the BlockReference is lost after the transaction is closed.
A bit of code explains it better :
Sub dummyExample()
'Lets grab a BlockReference based on a given ObjectId
Dim myBlockRef As BlockReference = findBlockRef(someObjectId)
'AutoCAD allows me to consult/call the properties & methods of the obtained BlockReference after this point
Console.WriteLine(myBlockRef.Name) 'AutoCAD = Ok with this
'Bricscad 'lost' reference to the BlockReference when the transaction in findBlockRef() was closed.
End Sub
'Dummy Function
Public Function findBlockRef(_acadBlockRefId As ObjectId) As BlockReference
Dim returnBlockRef As BlockReference
' Get the current document and database, and start a transaction
Dim acDoc As Document = Bricscad.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
' Lock the document
Using acLckDoc As DocumentLock = acDoc.LockDocument()
' Start a transaction in the new database
Using acTrans = acDoc.TransactionManager.StartTransaction()
returnBlockRef = acTrans.GetObject(_acadBlockRefId, OpenMode.ForRead)
' Commit the transaction
acTrans.Commit()
End Using ' Dispose of the transaction
End Using ' Unlock the document
Return returnBlockRef
End Function
So this might not be 'best-practice' in the first place ?
Why does AutoCAD & BricsCAD function differently here ?
What can I do to 'translate' my code best ?
Thanks for reading, any & all suggestions are welcome !
Regards,
Bert