rschader Posted December 16, 2004 Share Posted December 16, 2004 I am attempting my first use of the AutoIt ActiveX control from VBA from inside AutoDesk's Inventor CAD software. I first tested that the basic script commands work properly if run from outside the program. The script is simply: WinWaitActive("Drawing View") ControlCommand("","","SysTabControl321", "TabRight","") ControlClick("", "", "Button16", "left", 1) ControlClick("", "", "Button1", "left", 1) and it works fine. But if I try to do the same thing from within VBA after sending the command to Inventor first to display the required dialog window, the window only comes up INCOMPLETE and the program locks up. I know it should be possible for it to work this way, because if I uncomment the test that runs notepad, that works, and I could probably just use that to execute my compiled script instead, but I'd rather get everything to work right from within VBA. Hopefully someone can give me some pointers here to get this to work, I'm tried of waiting for AutoDesk to make their program API more accessible! Sub BreakAlignment() 'Create AutoIt Interface Set oAutoIt = CreateObject("AutoItX3.Control") 'this block of code just tells inventor to put up the dialog box I want to 'automate, which has the title "Drawing View". Dim oCtrlDef2 As ControlDefinition Set oCtrlDef2 = _ ThisApplication.CommandManager.ControlDefinitions _ ("DrawingViewEditCtxCmd") oCtrlDef2.Execute 'simply test if autoit multi-tasks in this context: 'oAutoIt.Run ("notepad.exe") ' that works, next code locks up. Call oAutoIt.WinWaitActive("Drawing View") Call oAutoIt.ControlCommand("", "", "SysTabControl321", "TabRight", "") Call oAutoIt.ControlClick("", "", "Button16", "left", 1) Call oAutoIt.ControlClick("", "", "Button1", "left", 1) End Sub TIA, Bob Link to comment Share on other sites More sharing options...
rschader Posted December 16, 2004 Author Share Posted December 16, 2004 Playing around with this somemore, I am able to make SOME progress getting it to work. First, I elimated the "Call" keywords and the WaitWinActive command and have attempted to add a ControlFocus command: oAutoIt.ControlCommand "Drawing View", "", "SysTabControl321", "TabRight", "" 'MsgBox "tabbed right" Dim FocusSuccess As Integer 'FocusSuccess = 0 'Do FocusSuccess = oAutoIt.ControlFocus("Drawing View", "", "Button16") 'Loop Until FocusSuccess = 1 MsgBox "FocusSuccess = " & FocusSuccess 'above line returns 0 BUT the msgbox delay allows next line to work anyway. oAutoIt.ControlCommand "Drawing View", "", "Button16", "UnCheck", "" 'oAutoIt.ControlClick "Drawing View", "", "Button1", "left", 1 I had to comment out the do loop start and end due to it locking up the program. It's almost like I need to run that in a separate thread somehow, which I am not sure how to do. Now it seems to be a matter of timing. If I have the msgboxes uncommented, then all seems to work by the delay introduced by them. But if I do not have them, I can not get focus or uncheck Button16. I think I will try adding a WinActivate command at the start, but other than that I am short on ideas to get the needed delays to work. Bob S. Link to comment Share on other sites More sharing options...
rschader Posted December 16, 2004 Author Share Posted December 16, 2004 (edited) OK. I finally got it to work correctly. I simply put a "DoEvents" statement inside my Do Loop, so it looks like this: Sub BreakAlignment() 'Create AutoIt Interface Set oAutoIt = CreateObject("AutoItX3.Control") ...other code here oAutoIt.ControlCommand "Drawing View", "", "SysTabControl321", "TabRight", "" Dim FocusSuccess As Integer Do FocusSuccess = oAutoIt.ControlFocus("Drawing View", "", "Button16") DoEvents Loop Until FocusSuccess = 1 oAutoIt.ControlCommand "Drawing View", "", "Button16", "UnCheck", "" oAutoIt.ControlClick "Drawing View", "", "Button1", "left", 1 End Sub Now that I have overcome this hurdle, I can hopefully start automating much more of Inventor! Edited December 16, 2004 by rschader Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now