CommandMethod CommandFlags Conundrum
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
My objective is to create a single command that opens a document, copies some info from inside of it, and then discards the document it opened. I want to do all of this from a single user command. Here's the gist of it:
<CommandMethod("MOCTB")>
Public Shared Sub runMOC()
Dim nd = Application.DocumentManager.Add("C:\mydwg.dwg")
Application.DocumentManager.MdiActiveDocument = nd
Dim ed As Editor = nd.Editor
ed.Command("COPYBASE", "0,0", "ALL", "")
'run further commands, etc.
'....
'now finish up
nd.CloseAndDiscard 'THIS line files with "drawing is busy"
End Sub
I understand that the line nd.CloseAndDiscard fails because the commandMethod needs the following parameter:
<CommandMethod("MOCTB", CommandFlags.Session)>
However with the CommandFlags.Session parameter set, the CloseAndDiscard works, but running ed.Command() now fails with "eInvalidInput"
<CommandMethod("MOCTB", CommandFlags.Session)> '<--needed for CloseAndDiscard to work
Public Shared Sub runMOC()
Dim nd = Application.DocumentManager.Add("C:\mydwg.dwg")
Application.DocumentManager.MdiActiveDocument = nd
Dim ed As Editor = nd.Editor
ed.Command("COPYBASE", "0,0", "ALL", "") 'now this line fails with "eInvalidInput"
'run further commands, etc.
'....
'now finish up
nd.CloseAndDiscard
End Sub
How can I open a document, make changes in the document context, and then close it from the session context?
Any help is appreciated.