How to switch documents while a command is running
Hello.
I created a command to get points.
<CommandMethod("test")>
Public Shared Sub test()
Dim editor As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim pop As New PromptPointOptions("Select Point")
Application.ShowAlertDialog(editor.GetPoint(pop).ToString)
End Sub
It is not possible to switch documents during user operations.
The "LINE" command allows you to switch documents.(Switching documents will end the command.)
I would like the custom command to be the same as the "LINE" command.
Is there a way to switch documents with a custom command, just like with the "LINE" command?
Comments
-
Usually, you would have to run the command in a session context, Caveat, you may have to add document locks.
Note, if the line command allows for document switching, that seems like a bug
0 -
Thank you for your reply.
I tried "CommandFlags.Session", but it didn't solve the problem.<CommandMethod("test", CommandFlags.Session)>
Public Shared Sub test()
Using docLock As DocumentLock = Bricscad.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument()
Dim editor As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim pop As New PromptPointOptions("Select Point")
Application.ShowAlertDialog(editor.GetPoint(pop).ToString)
End Using
End SubThe problem is occurring in BricsCAD V25.
→BricsCAD version:V25.1.06As a side note, in V19, custom commands worked the same as the "LINE" command.
0 -
I used the "DocumentToBeDeactivated" event but it didn't work.
<CommandMethod("test", CommandFlags.Session)>
Public Shared Sub test()
Using docLock As DocumentLock = Bricscad.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument()
Dim editor As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim pop As New PromptPointOptions("Select Point")
Application.ShowAlertDialog(editor.GetPoint(pop).ToString)
End Using
End Sub
<CommandMethod("AddDocumentToBeDeactivated", CommandFlags.Session)>
Public Shared Sub AddDocumentToBeDeactivated()
AddHandler Bricscad.ApplicationServices.Application.DocumentManager.DocumentToBeDeactivated, AddressOf OnDocDeactivated
End Sub
<CommandMethod("RemoveDocumentToBeDeactivated", CommandFlags.Session)>
Public Shared Sub RemoveDocumentToBeDeactivated()
RemoveHandler Bricscad.ApplicationServices.Application.DocumentManager.DocumentToBeDeactivated, AddressOf OnDocDeactivated
End Sub
Private Shared Sub OnDocDeactivated(sender As Object, e As DocumentCollectionEventArgs)
Dim editor As Editor = Application.DocumentManager.MdiActiveDocument.Editor
editor.WriteMessage(vbLf & "MdiActiveDocument {0}:", New Object() {Application.DocumentManager.MdiActiveDocument.Name})
End SubSTEP1: Execute the "AddDocumentToBeDeactivated" command.
STEP2: Execute the "test" command.
STEP3: I try to switch drawings during the "GetPoint" operation.
RESULT: The drawing does not switch. The "DocumentToBeDeactivated" event does not occur.
It looks like drawing switching is disabled. Is there a way to enable drawing switching?
I'm really in trouble.
Do you have any information?
0 -
Sorry, it seems CAD is becoming stricter with document switching. The only way I’ve found that works is to use the document manager to switch documents.
@Ap.Command("doit", Ap.CmdFlags.SESSION ) def doit() -> None: try: man = Ap.DocManager() docs = man.documents() man.setCurDocument(docs[0],Ap.DocLockMode.kNone,True) print(docs[0].fileName()) ps, pnt1 = Ed.Editor.getPoint("\nSelect Point") man.setCurDocument(docs[1],Ap.DocLockMode.kNone,True) print(docs[1].fileName()) ps, pnt2 = Ed.Editor.getPoint("\nSelect Next Point") except Exception as err: traceback.print_exception(err)
: DOIT
Drawing1.dwg Select Point Drawing2.dwg Select Next Point0 -
Thanks for your reply.
However, that wasn't what I wanted.
I did some further research.
I was able to achieve what I wanted using "BRXSDK."
It seems this isn't possible with ".NetAPI."
Please let me know if you have any additional information.
0