Jump to content

Automation not working with some software


Go to solution Solved by junkew,

Recommended Posts

Can you please post the output of the AutoIt Window Info Tool when you move the cross hair pointer over a control?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Here is the code:

; make Mach3 active
WinActivate("Mach3 CNC  Demo","")


; Wait for the Mach3 to become active -
WinWaitActive("Mach3 CNC  Demo")

;try mouse click to initiate cycle start
MouseClick("primary", 95, 587, 2)

;Try  control click to click cyclestart button
ControlClick ( "Mach3 CNC  Demo", "",8631)

; try sending ctrl r to cycle start
Send("!r")

; Check if Mach3 window is active
Local $state = WinGetState("Mach3 CNC  Demo", "")

; Is the "active" value set?
If BitAND($state, 8) Then
    MsgBox(0, "Example", "Window is Active")
EndIf

; Finished!
; Tried each method individually and all together with no result
;Have gcode loaded in mach3 window and can see if the cycle advances
;ctrl r on keyboard or clicking the button advances gcode
;Oddly if window is minimised it does not bring it up but says it is active

Link to comment
Share on other sites

Output of window tool

Window

Mach3 CNC  Demo

Afx:00400000:b:00010007:00000006:05C90219

-8, -8

1419, 1147

0x15CF0000

0x00000100

0x00030748

Control with finder tool over button

Static9

[CLASS:Static; INSTANCE:9]

8631

7, 7

1902, 1052

71, 594

0x54000000

0x00000000

0x00010C5C

Link to comment
Share on other sites

Looks like your controlclick command wasnt correct...Try this:

; wait for Mach3 to be active
WinWaitActive("Mach3 CNC  Demo","")

;Try  control click to click cyclestart button
ControlClick("Mach3 CNC  Demo", "", "[CLASS:Static; INSTANCE:9]")

Edit: I guess i shouldnt say it wasnt correct. I just use it differently (above)

Edited by Shrapnel
Link to comment
Share on other sites

Add some error checking to your code. Every function returns a value or sets macro @error. Check if the values are as expected.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thankyou for your responses.

I tried the suggested code;

; wait for Mach3 to be active WinWaitActive("Mach3 CNC  Demo","") ;Try  control click to click cyclestart button ControlClick("Mach3 CNC  Demo", "", "[CLASS:Static; INSTANCE:9]", "left", 1)
 
It did not work either.
 
I added an error check and it did flag an error after winactivate. @extended just shows 0
It also flagged an error with winwaitactive.
it also flagged an error from the controlclick function which is probably because the window is not active but checking for it being active gives a positive result.
 
Thanks
 
 
Link to comment
Share on other sites

That may be some sort of container class control that is not letting you click on the exact button you want.  If Au3Info can't see the button you are probably referencing the container.  Here is another idea: A brief review of the Mach3 documentation suggests you can configure hotkeys.  If you do that you could use "Send" to send the keys for the commands you are trying to run.  Not sure if it would work but may be worth trying. :D

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

Tried the controlsend with no success. I think the issue is that winactivate and winwaitactive are not working as they are returning errors even though the window shows active. Is it possible that Mach3 is somehow blocking any access to the window?

Link to comment
Share on other sites

Thanks for installing Mach3. I will need to understand the link you provided to try what you did- I am very much a novice with this tool. Would you mind testing if you can get the script to work in Mach3? Just add a couple of lines of gcode in notepad as a text file eg:

f600
g1 Z-2
g1 y-13.5
g1 z-14
g1 z-26
g1 z-38
g1 y-35

After loading the gcode just press alt-n to get it into step mode- one line at a time.

Then when you press alt-r or the button you will see the code go to the next line. If you can get it to do that through your script file- wow that would be a solution to my problem. I have so far been unable to do it.

Appreciate your help

Thanks

Link to comment
Share on other sites

Sorry for harping on this topic but does anyone have any suggestions on how I should proceed or does it look like Mach3 cannot be automated with scripts? I did contact the company. They made a statement that Mach3 cannot be controlled by any other software without writing a plugin. Not sure I understand how they are blocking it but if nobody has any suggestions I will see if someone can write a plugin for me.

Thanks

Link to comment
Share on other sites

Works perfectly with the library I am making in AutoIT

'?do=embed' frameborder='0' data-embedContent> title="">

Still working on that library to enhance it to recognize with more properties and shortening code

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <constants.au3>
#include <WinAPI.au3>
#include <debug.au3>
#include "CUIAutomation2.au3"
#include "UIAWrappers.au3"
HotKeySet("{ESC}", "Terminate")

;~ Turn debugging UIA on by default, dumps most details to consolewindow for the moment, later will use a logfile
;~ _UIA_setVar("Global.Debug",true)
;~ _UIA_setVar("Global.Highlight",true) ;- Highlights object when found

;~ Set the system under test variables
_UIA_setVar("SUT1.Folder","C:\Mach3")
_UIA_setVar("SUT1.Workingdir","C:\Mach3\")
_UIA_setVar("SUT1.EXE","Mach3.exe")
_UIA_setVar("SUT1.Fullname", _UIA_getVar("SUT1.Folder") & "\"& _UIA_getVar("SUT1.EXE"))
_UIA_setVar("SUT1.Parameters","/p Mach3Mill")
_UIA_setVar("SUT1.Processname","mach3.exe")
_UIA_setVar("SUT1.Windowstate",@SW_RESTORE)

_UIA_setVar("SUT1.Fullname", _UIA_getVar("SUT1.Folder") & "\"& _UIA_getVar("SUT1.EXE"))

;~ Set the system under test objects to recognize
_UIA_setVar("MACH3.mainwindow","name:=Mach3 CNC*")
_UIA_setVar("MACH3.editgcode","name:=Edit G-Code")
_UIA_setVar("MACH3.btnCyclestart","automationid:=8142")
_UIA_setVar("MACH3.mnuFile","name:=((File)|(Bestand)) index:=2")
_UIA_setVar("MACH3.mnuOpen","name:=Load*")

_UIA_setVar("MACH3.dlgOpen","name:=Open*")
_UIA_setVar("MACH3.dlgOpen.edtFilename","name:=((Filename:)|(Bestandsnaam:)) indexrelative:=2")
_UIA_setVar("MACH3.dlgOpen.btnOpen","name:=Open* index:=6")

_UIA_setVar("NOTEPAD.mainwindow","classname:=Notepad")
_UIA_setVar("NOTEPAD.edit","classname:=Edit")
_UIA_setVar("NOTEPAD.mnuFile","name:=((File)|(Bestand))")
_UIA_setVar("NOTEPAD.mnuSave","name:=((Save*)|(Opslaan*))")
_UIA_setVar("NOTEPAD.btnClose","name:=((Close)|(Sluiten))")

_UIA_setVar("NOTEPAD.dlgSave","name:=((Save as*)|(Opslaan als*))")
_UIA_setVar("NOTEPAD.dlgSave.edtFilename","name:=((Filename:)|(Bestandsnaam:)) indexrelative:=1")
_UIA_setVar("NOTEPAD.dlgSave.btnSave","name:=((Save)|(Opslaan)) index:=4")
_UIA_setVar("NOTEPAD.dlgSave.btnYes","name:=((Yes)|(Ja))")

;~ Start system under test
_UIA_DEBUG("Starting system under test" & @CRLF)
_UIA_StartSUT("SUT1")
_UIA_DEBUG("SUT is started" & @CRLF)

_UIA_DEBUG(_UIA_getVar("SUT1.PID"))

;~ Get the main WMP element
_UIA_DEBUG("Action 1 Finding main window" & @CRLF)
$oMACH3=_UIA_getObjectByFindAll($oDesktop, _UIA_getVar("MACH3.mainwindow"), $treescope_children)
$oMACH3.setfocus()

_UIA_DEBUG("Action 2 Clicking the edit G-Code button" & @CRLF)
$oEditBtn=_UIA_getFirstObjectOfElement($oMACH3, _UIA_getVar("MACH3.editgCode"), $treescope_subtree)
_UIA_action($oEditBtn,"left")

_UIA_DEBUG("Action 3 Finding the edit / notepad window" & @CRLF)
$oNotepad=_UIA_getObjectByFindAll($oDesktop, _UIA_getVar("NOTEPAD.mainwindow"), $treescope_children)
$oNotepad.setfocus()

_UIA_DEBUG("Action 4 Write a script" & @CRLF)
$oEdit=_UIA_getFirstObjectOfElement($oNOTEPAD, _UIA_getVar("NOTEPAD.edit"), $treescope_subtree)
_UIA_action($oEdit,"sendkeys","f600{ENTER}g1 Z-2{ENTER}g1 y-13.5{ENTER}g1 z-14{ENTER}g1 z-26{ENTER}g1 z-38{ENTER}g1 y-35{ENTER}")
$o=_UIA_getObjectByFindAll($oNOTEPAD, _UIA_getVar("NOTEPAD.mnuFile"), $treescope_subtree)
_UIA_action($o,"left")

_UIA_DEBUG("Action 5 Save the script" & @CRLF)
$o=_UIA_getObjectByFindAll($oNOTEPAD, _UIA_getVar("NOTEPAD.mnuSave"), $treescope_subtree)
_UIA_action($o,"left")

$odlgSave=_UIA_getObjectByFindAll($oNOTEPAD, _UIA_getVar("NOTEPAD.dlgSave"), $treescope_subtree)
$o=_UIA_getObjectByFindAll($odlgSave, _UIA_getVar("NOTEPAD.dlgSave.edtFilename"), $treescope_subtree)
$o.setfocus()
_UIA_action($o,"sendkeys","demofile.txt")

$o=_UIA_getObjectByFindAll($odlgSave, _UIA_getVar("NOTEPAD.dlgSave.btnSave"), $treescope_subtree)
_UIA_action($o,"left")

_UIA_DEBUG("Action 5a If there is a duplicate file " & @CRLF)
$o=_UIA_getObjectByFindAll($odlgSave, _UIA_getVar("NOTEPAD.dlgSave.btnYes"), $treescope_subtree)
if isobj($o) Then
    _UIA_action($o,"left")
EndIf

$o=_UIA_getObjectByFindAll($oNOTEPAD, _UIA_getVar("NOTEPAD.btnClose"), $treescope_subtree)
_UIA_action($o,"left")

_UIA_DEBUG("Action 6 Open the script" & @CRLF)
$o=_UIA_getObjectByFindAll($oMACH3, _UIA_getVar("MACH3.mnuFile"), $treescope_subtree)
_UIA_action($o,"left")
$o=_UIA_getObjectByFindAll($oMACH3, _UIA_getVar("MACH3.mnuOpen"), $treescope_subtree)
_UIA_action($o,"left")

$odlgOpen=_UIA_getObjectByFindAll($oMach3, _UIA_getVar("MACH3.dlgOpen"), $treescope_subtree)
$o=_UIA_getObjectByFindAll($odlgOpen, _UIA_getVar("MACH3.dlgOpen.edtFilename"), $treescope_subtree)
$o.setfocus()
_UIA_action($o,"sendkeys","demofile.txt")
sleep(250)

$o=_UIA_getObjectByFindAll($odlgOpen, _UIA_getVar("MACH3.dlgOpen.btnOpen"), $treescope_subtree)
_UIA_action($o,"left")
sleep(1000) ;~ Just 1 second to be able to load the script

_UIA_DEBUG("Action 7 Start the cycle" & @CRLF)
$o=_UIA_getObjectByFindAll($oMACH3, _UIA_getVar("MACH3.btnCycleStart"), $treescope_subtree)
_UIA_action($o,"left")


; The End
Func Terminate()
    consolewrite("Exiting")
    $running=false
;~  Exit 0
EndFunc   ;==>Terminate
Edited by junkew
Link to comment
Share on other sites

Hi Junkew,

I get the following error when I run the script.

Line 209 in UIAwrappers.au3

$obj.GetCurrentPropertyValue($Id,$tVal)

$obj ^ Error

Error Varibles must be of type object

Sorry but this level of programming is above my skillset and I am not sure if I am doing something wrong or there is an error in the include file.

I copied the attachements to the include directory and ran the script you sent. It did bring the mach3 window to the front but then stopped due to this error.

Thanks

Ravi

Link to comment
Share on other sites

As you probably have a different language as I am using (I have a dutch windows) its hard to debug from a distance

What do you see exactly in the consolewindow?

0. A number (the command _UIA_DEBUG(_UIA_getVar("SUT1.PID")))

1. Action 1 Finding main window

2. Action 2 Clicking the edit G-Code button

  • Start with reading the basics of advanced windows as the main UIA framework follows the same concept

http://www.autoitscript.com/autoit3/docs/intro/windowsadvanced.htm

  • Each and every GUI element of windows is having properties which can be used to identify an GUI element

name or title is probably the easiest to understand

1.In the sample code I prefer to give a logical name to a physical description

So MACH3.MAINWINDOW is just a logical name for name:=Mach3 CNC.* where the dot followed by a star means any character 0,1,n times

2. Before you can do something with an GUI element you have to get a reference to the GUI element by finding it

$oMACH3=_UIA_getObjectByFindAll($oDesktop, _UIA_getVar("MACH3.mainwindow"), $treescope_children)

means put in the variableHandle $oMach3 a reference to the Mach3 window

by using the function _UIA_getObjectByFindAll that scans all elements from the desktop that are 1 level deep as given by $treescope_children

3. Once you have the handle you want to do an action on the object

_UIA_action($oEditBtn,"left")

means press the left mouse button on the object thats referenced by $oEdtBtn

and to make the definitions like

_UIA_setVar("MACH3.btnCyclestart","automationid:=8142")

its sometimes hard to define this

You need the simple script spy of the other thread

hover over the object and press ctrl+w

Feel free to post more details an I will try to help

Link to comment
Share on other sites

I realy thank you for your effort. I must be doing something wrong. I compiled the script with console selected and ran it with mach3 open. It started dumping the tree to the console and appeared to dump data on  bunch of the programs on my computer before it errorred out.

Do I need to be doing something else besides compiling the script and running the exe?

I added the latest files to the include directory.

Sorry for the trouble

Thanks

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...