Hi,
I have a program that switches to an active document and prompts to select a block. It worked in 2014 but in 2016 it just passes right over the prompt without firing. I understand I need to use something like ExecuteInCommandContextAsync.. Can someone give me a vb.net example of its use. I have something in C# to pick a point but I can't translate to anything useful in vb.net.
Thanks in Advance
Solved! Go to Solution.
Solved by norman.yuan. Go to Solution.
Hi,
Try below code
<CommandMethod("MyGroup", "MyCommand", "MyCommandLocal", CommandFlags.Session)> _ Public Async Sub MyCommand() ' This method can have any name Await Application.DocumentManager.ExecuteInCommandContextAsync(AddressOf CallAcadCommands, Application.DocumentManager) End Sub Public Async Function CallAcadCommands(p As Object) As System.Threading.Tasks.Task Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor Await ed.CommandAsync("_.Line") Await ed.CommandAsync("0,0") Await ed.CommandAsync("10,10") Await ed.CommandAsync("") End Function
Hi,
Thanks for the response. Maybe I am asking for an example of the wrong method or I don't understand. I need to switch to a different open drawing then select an object so I can get its object ID. Using commands I don't see how this is possible. Do I need ExecuteInApplicationContext instead? and if so what would that look like? Basically I am trying to get the code below to execute when it is hit. Right now it just passes right over getselection. without prompting for objects to select.
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument Dim ed As Editor = doc.Editor Dim pso As New PromptSelectionOptions() Dim psr As PromptSelectionResult = ed.GetSelection(pso)
Thanks again.
Yes, the the operation (starting a command from a drawing, then switch to another drawing opened in AutoCAD for some sort of user interaction and then switch back to the drawing where the command is started) was OK prior to AutoCAD2014 (inclusive). AutoCAD 2015 has broken this behaviour due to removal of "FIBER". That is, when MdiActiveDocument in AutoCAD is switched, the currently executing command will be cancelled.
I ran into this issue when my office moved up to AutoCAD 2015, because we had some CAD apps doing similar things as you described: the CAD apps need to get some data from other drawing by asking user to selecting something in the other drawing.
There are 2 ways (at least 2 ways I tried) to deal with this:
1. Do not have the data source drawing (user is to select something from it) pre-opened in AutoCAD. Rather, you can open it during the command execution and then after user selecting close it.
2. Create multiple commands and chain them together by handling appropriate DocumentCollection/Document and pass the data between commands with static variables.
After I ran into this issue and update the apps we use, I thought I would write this issue in my blog but never found time to finish the article. Now that I saw your question, I thought there could be others who would also come across the same issue. So, I picked what I had left before in the past weekend. While I have not finished it due to my busy weekend activities, I should be able to post it shortly, maybe later today, or tomorrow. Of course you can explore further based on the above 2 tips, if you do not want to wait to see what I have done.
Norman Yuan
Hi Norman,
Thanks for the reply. I'm looking forward to reading your blog on the matter. One thing I noticed is that once the drawing is opened by the program and you switch to it, the program can flip back and forth between this newly opened drawing and the previous drawing several times without stopping.
Thanks Again.
OK, here is the first article on this topic:
http://drive-cad-with-code.blogspot.ca/2017/04/asking-user-to-select-entity-in-other.html
Norman Yuan
Here is the second post on this topic:
http://drive-cad-with-code.blogspot.ca/2017/04/asking-user-to-select-entity-in-other_4.html
Sorry for the code being in C#, while you asked for VB.NET. However, you can easily use online C#<->VB.NET converter, to copy/paste/convert the code, such as here:
HTH
Norman Yuan