<CommandMethod("C2TMP", CommandFlags.Session)> _
Public Sub C2TMP()
Instellingen()
Copy2Template(oAppAutocadDWT, oAppMechanicalDWT, oAppCivilDWT)
End Sub
Public Sub Copy2Template(ByVal oAppAutocadDWT As String, ByVal oAppMechanicalDWT As String, ByVal oAppCivilDWT As String)
Dim acObjIdColl As ObjectIdCollection = New ObjectIdCollection()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Dim acDocEd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim acDocMgr As DocumentCollection = Application.DocumentManager
Dim acSSPrompt As PromptSelectionResult
acSSPrompt = acDocEd.SelectAll()
Dim acSSet As SelectionSet = acSSPrompt.Value
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
For Each oSel As SelectedObject In acSSet
acObjIdColl.Add(oSel.ObjectId)
Next
acTrans.Commit()
End Using
Dim sTemplatePath As String = oAppAutocadDWT
Dim oCadVer As String = Left(Right(SystemObjects.DynamicLinker.ProductKey, 7), 3)
If oCadVer = "001" Then 'Autocad
sTemplatePath = oAppAutocadDWT
ElseIf oCadVer = "000" Then 'Civil
sTemplatePath = oAppCivilDWT
ElseIf oCadVer = "005" Then 'Mechanical
sTemplatePath = oAppMechanicalDWT
End If
Dim acNewDoc As Document = acDocMgr.Add(sTemplatePath)
Dim acDbNewDoc As Database = acNewDoc.Database
Using acLckDoc As DocumentLock = acNewDoc.LockDocument()
Using acTrans = acDbNewDoc.TransactionManager.StartTransaction()
Dim acBlkTblNewDoc As BlockTable
acBlkTblNewDoc = acTrans.GetObject(acDbNewDoc.BlockTableId, OpenMode.ForRead)
Dim acBlkTblRecNewDoc As BlockTableRecord
acBlkTblRecNewDoc = acTrans.GetObject(acBlkTblNewDoc(BlockTableRecord.ModelSpace), OpenMode.ForRead)
Dim acIdMap As IdMapping = New IdMapping()
acCurDb.WblockCloneObjects(acObjIdColl, acBlkTblRecNewDoc.ObjectId, acIdMap, DuplicateRecordCloning.Ignore, False)
acTrans.Commit()
End Using
End Using
acDoc.CloseAndDiscard()
acDocMgr.MdiActiveDocument = acNewDoc
End Sub Insetllingen gets some parameters from an xml file (this works)
Then it calls to Copy2Template
Everything goes great untill the part acdoc.closeanddiscard() i get the error Drawing is busy!
I've added the CommandFlags.Session to the command as you suggested.
After the Copy2Template i need to run some more code (wich i already have but not included in this command) in the new document