By Adam Nagy
If you start a transaction inside your main function, then you do not need to create another one (a sub transaction) inside your sub function, you do not even need to pass the transaction to the sub function, you can simply use ObjectId.GetObject() instead, which will automatically use the outer transaction you started.
Public Sub MoveBlock( _
ByRef blockRefId As ObjectId, _
ByVal newLocation As Point3d)
Dim blockRef As BlockReference = _
blockRefId.GetObject(OpenMode.ForWrite)
blockRef.Position = newLocation
End Sub
<CommandMethod("MoveBlockCommand")> _
Public Sub MoveBlockCommand()
Dim ed As Editor = _
Application.DocumentManager.MdiActiveDocument.Editor
Dim perEntity As PromptEntityResult = _
ed.GetEntity("Select block to move: " + vbCrLf)
If perEntity.Status <> PromptStatus.OK Then Return
Dim pprPoint As PromptPointResult = _
ed.GetPoint("Pick the new position for the block: " + vbCrLf)
If pprPoint.Status <> PromptStatus.OK Then Return
Dim db As Database = HostApplicationServices.WorkingDatabase
Using tr As Transaction = db.TransactionManager.StartTransaction
MoveBlock(perEntity.ObjectId, pprPoint.Value)
tr.Commit()
End Using
End Sub