Add the CommandFlags.Session flag to your CommandMethod attribute and lock the new document before starting the transaction:
Code:
<CommandMethod("LineInNewDrawing", CommandFlags.Session)> Public Sub AccessSpaceModel()
Dim acDwt As String = "acadiso.dwt"
Dim acDocMgr As DocumentCollection = Application.DocumentManager
Dim acDocDwt As Document = acDocMgr.Add(acDwt)
acDocMgr.MdiActiveDocument = acDocDwt
'' Get the current document and database
''Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDocDwt.Database
'' Lock the document
Using acDocDwt.LockDocument()
'' Start a transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'' Open the Block table for read
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
'' Open the Block table record for read
Dim acBlkTblRec As BlockTableRecord
' Get the ObjectID for Model space from the Block table
acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
'ElseIf pKeyRes.StringResult = "Paper" Then
'' Create a line that starts at 2,5 and ends at 10,7
Dim acLine As Line = New Line(New Point3d(2, 5, 0), New Point3d(10, 7, 0))
acLine.SetDatabaseDefaults()
'' Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acLine)
acTrans.AddNewlyCreatedDBObject(acLine, True)
'' Save the new line to the database
acTrans.Commit()
End Using
End Using
End Sub