TheSwamp
Code Red => VB(A) => Topic started by: MSTG007 on March 27, 2019, 12:08:50 PM
-
I have this vba code that I use to use with AutoCAD 2015. It was able to activate a command in autocad that would bring up a dialog box. Then it would proceed with the sendkeys on that dialog box.
I am trying the same thing in 2018 and the sendkeys do not work on the dialog box. However, when I close the dialog box, it runs the sendkeys at the command line. Not quite sure whats going on.
Thank you for any help!
Sub Catchment()
On Error Resume Next
Set AcadApp = GetObject(, "AutoCAD.Application")
If Err Then
Err.Clear
Set AcadApp = CreateObject("AutoCAD.Application")
End If
AppActivate AcadApp.Caption
AcadApp.Visible = True
AcadApp.Application.WindowState = acNorm
AcadApp.ActiveSpace = acModelSpace
If AcadApp.Documents.Count = 0 Then
AcadApp.Documents.Add
End If
AcadApp.ActiveDocument.SendCommand "_CREATECATCHMENTFROMOBJECT" & vbCr
End Sub
Sub Catchment_Storm_SendKeys()
Dim myApp As String
DoEvents
Application.Wait (Now + TimeValue("0:00:01"))
Sleep 250
SendKeys "{TAB}{TAB}{TAB}{TAB}", True
Sleep 250
SendKeys "{ENTER}", True
Sleep 250
SendKeys "{TAB}{TAB}{TAB}{TAB}", True
End Sub
-
lol. This is funny. I did not realized I asked this a few years ago.
http://www.theswamp.org/index.php?topic=49598.msg547399#msg547399 (http://www.theswamp.org/index.php?topic=49598.msg547399#msg547399)
-
lulz. Cue the "I have alzheimer's but at least I don't have alzheimer's" memes.
Back to your issue -- is it a case of modal vs non-modal -- i.e. it would work properly in the latter?
-
It is modal. I have to click the OK button to dismiss it.
-
Is there a way I can change a focus to the dialog box by targeting the title in the dialog box?
-
Is there a way I can change a focus to the dialog box by targeting the title in the dialog box?
https://stackoverflow.com/a/30353590 (https://stackoverflow.com/a/30353590)
That link is referring to Excel, but in the same way Autocad/VBA will not process the remaining vba statements until the modal dialog is dismissed.
-
Im trying to follow. So I can not get the handle of the modal window, but I can place a timer for the VBA to wait until out of the window? Something like that?
-
... for the VBA to wait until out of the window ...
I don't see it that way. It appears that you won't be using the AutoCAD/VBA function SendKeys, but the Windows API SendMessage function. The timer is a 10 millisecond delay to allow the dialog to show before the TIMERPROC is called. The TIMERPROC function gets a handle to the dialog using FindWindow call and then issues a SendMessage to it.
Here are a couple of links that you might find useful:
https://www.google.com/search?q=windows+message+pump+vba&rlz=1C1GCEU_enUS820US820&oq=windows+message+pump+vba&aqs=chrome..69i57.8716j0j8&sourceid=chrome&ie=UTF-8
https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-settimer
Years ago I used Spy++ to see the Messages that are passed in the operating system...
https://docs.microsoft.com/en-us/visualstudio/debugger/introducing-spy-increment?view=vs-2017