Sign in to follow this  
Followers 0
sonali

Automation of windows application is stopping and need to loop it when it stops

8 posts in this topic

Hi All,

the below script is getting stopped

either   

  FileWriteLine($file,"Error: Cannot Get the Handle of Image")

OR

FileWriteLine($file,"Error: Cannot get Handle of the output Image")

please help me to to loop this til this becomes false.

#include "InputHeader_BMP.au3"
Local $strErrorLogName = 'WINAPP_CurveFitting_Constant_BMP_Win7.txt'
Local $strErrorLogPathName = $strErrorLogPath&$strErrorLogName

Global $iKernelWidth = '3'
Global $iKernelHeight = '3'
Global $iLowerThreshold = '200'
Global $iUpperThreshold = '250'
Global $iMinEllipseRadius = '10'
Global $iSleepTime = 500

Global $file = FileOpen($strErrorLogPathName,2)
if($file == -1) Then
    MsgBox(0, "Error", "Unable to open the file")
    Exit
EndIf

Run($strApplicationPath)
For $iOperation = 0 To 3 Step 1
    Main($strInputImgPath1k,$strName1k,$strName8bits,$iOperation)
    
Next

Local $strActive = WinActive("WINAPP", "Ready")
if @error == 0 Then
    Winclose("WINAPP")
EndIf
Func Main($strInpPath,$strImgName,$strOutPath,$iOperation)
Local $reset = 0
Local $reset1 = 0

Local $winapp = WinWait("WINAPP", "Ready")
if $winapp == 0 Then
    FileWriteLine($file,"Run-WINAPP.exe: Unable to Open WINAPP")
    FileWriteLine($file," ")
Else
    WinActivate($winapp)
    FileWriteLine($file,"Run-WINAPP.exe: Application is running")
    FileWriteLine($file," ")

    If($iOperation == 0)Then
        FileWriteLine($file,"::::::::::::::::Ellipse::::::::::::::::")
    ElseIf($iOperation == 1)Then
        FileWriteLine($file,"::::::::::::::::Circle fit::::::::::::::::")
    ElseIf($iOperation == 2)Then
        FileWriteLine($file,"::::::::::::::::2nd Order fit::::::::::::::::")
    ElseIf($iOperation == 3)Then
        FileWriteLine($file,"::::::::::::::::3rd Order fit::::::::::::::::")
    EndIf

    For $i = 1 to 4 Step 1
        Local $str1 = String($i)
        Local $str2 = $strImgName
        Local $str3 = $str2&$str1
        Local $str4 = '.bmp'
        Local $str5 = $str3&$str4

        $ctrlClk = ControlClick("WINAPP","",59398,"left",1,$iXClickFile,$iYClickFile)
        If $ctrlClk == 0 Then
            FileWriteLine($file,"Controlclick file failure")
             ;CtrlClick()
        Else
            FileWriteLine($file,"Controlclick File Success")
            sleep($iSleepTime)
            $ctrlClk1 = ControlClick("WINAPP","",59398,"left",1,$iXClickOpen,$iYClickOpen)
            If $ctrlClk1 == 0 Then
                FileWriteLine($file,"Controlclick Open Failure")
            Else
                FileWriteLine($file,"Controlclick Open Success")
                Local $winopen = WinWait("Open","")
                if $winopen == 0 Then
                    FileWriteLine($file, "Control-Open:   Open Image button Fail")
                Else
                    WinActivate ($winopen)
                    FileWriteLine($file, "Control-Open:   Open Image button Success")
                    sleep($iSleepTime)
                    Local $str6 = $strInpPath&$str5
                    sleep($iSleepTime)
                    Local $strOpenIm1 = ControlSetText("Open", "","Edit1",$str6)
                    Sleep($iSleepTime)
                    if($strOpenIm1 == 0) Then
                        FileWriteLine($file,"Error: Set Image Path Fail")
                        sleep($iSleepTime)
                        Send("{ESC}")
                    Elseif($strOpenIm1 == 1) Then
                        FileWriteLine($file,"Set Image1 Path Success")
                        send("{Enter}")
                        sleep($iSleepTime)
                        Local $str7 = 'Warning:  '&$str5&' is already open'
                        Local $str8 = $str5&' is ready for the process'
                        Local $a2 = WinExists("WINAPP","This Window is already open")
                        if $a2 == 1 Then
                            FileWriteLine($file,$str7)
                            send("{Enter}")
                            $reset = 0
                        ElseIf $a2 == 0 Then
                            $reset = 1
                        EndIf
                        Local $a11 = WinExists("WINAPP","Unable to load the image.")
                        if $a11 == 1 Then
                            FileWriteLine($file,"Error: Unable to Load Image")
                            send("{ENTER}")
                            $reset1 = 0
                        Else
                            $reset1 = 1
                        EndIf
                        if(($reset == 1) AND($reset1 == 1)) Then
                            Global $winHandle1 = ControlGetHandle("[Active]","","[ID:65280]")
                            if @error == 1 Then
                                FileWriteLine($file,"Error: Cannot Get the Handle of Image1")
                            Else
                                FileWritELine($file,"Get Handle of Image1 Success")
                                ControlHide("[Active]","","[ID:65280]")
                                CurveFitting($str3,$strOutPath,$iOperation)
                            EndIf
                        EndIf
                        FileWriteLine($file,"")
                    EndIf
                EndIf
                WinClose($winHandle1)
            EndIf
        EndIf
        sleep($iSleepTime)
    Next
EndIf
EndFunc

Func CurveFitting($str3,$strOutPath,$iType)
    Local $strOut =  $strOutputImgPath&$strOutPath&$str3
    Local $reset = 0
    $ctrlClk2 = ControlClick("WINAPP","",59398,"left",1,$iXClickOperation,$iYClickOperation)
    If $ctrlClk2 == 0 Then
        FileWriteLine($file,"Controlclick Operation Failure")
    Else
        FileWriteLine($file,"Controlclick Operation Success")
    sleep($iSleepTime)
    $ctrlClk3 = ControlClick("WINAPP","",59398,"left",1,$iXClickCurveFitting,$iYClickCurveFitting)
    If $ctrlClk3 == 0 Then
            FileWriteLine($file,"Controlclick Curve Fitting Failure")
        Else
            FileWriteLine($file,"Controlclick Curve Fitting Success")
    sleep($iSleepTime)
    Local $wincurvefitting = WinGetHandle("WINAPP","Curve Fitting")
    If @error Then
        FileWriteLine($file, "Curve Fitting Menu Not Available")
    Else
        ControlCommand($wincurvefitting,"", "ComboBox2", "ShowDropDown", "")
        sleep($iSleepTime)
        ControlCommand($wincurvefitting,"", "ComboBox2",  "SetCurrentSelection", $iType)
        If @error == 1 Then
            FileWriteLine($file, 'Error: ComboBox2 Fail')
        Else
            FileWriteLine($file, 'ComboBox2: select input')
        EndIf
        sleep($iSleepTime)
        ControlClick($wincurvefitting,"","ComboBox2")
        sleep($iSleepTime)

        $strCombo3 = $str3&'.bmp'
        Sleep($iSleepTime)
        ControlCommand($wincurvefitting,"", "ComboBox3", "ShowDropDown", "")
        sleep($iSleepTime)
            ControlCommand($wincurvefitting, "", "ComboBox3", "SelectString", $strCombo3)
        If @error == 1 Then
            FileWriteLine($file, 'Error: ComboBox3 Fail')
        Else
            FileWriteLine($file, 'ComboBox3: Select Image1 Success')
        EndIf
        sleep($iSleepTime)
        ControlClick($wincurvefitting,"","ComboBox3")
        sleep($iSleepTime)

        Local $settext = ControlSetText($wincurvefitting,"","Edit1",$iKernelWidth)
        if ($settext == 0) Then
            FileWriteLine($file,"Error: Set Kernal Width Fail")
        Else
            FileWriteLine($file,"Set Kernel Width Success")
        EndIf
        Local $settext = ControlSetText($wincurvefitting,"","Edit2",$iKernelHeight)
        if ($settext == 0) Then
            FileWriteLine($file,"Error: Set Kernal Height Fail")
        Else
            FileWriteLine($file,"Set Kernel Height Success")
        EndIf
        Local $settext = ControlSetText($wincurvefitting,"","Edit3",$iLowerThreshold)
        if ($settext == 0) Then
            FileWriteLine($file,"Error: Set Lower Threshold Fail")
        Else
            FileWriteLine($file,"Set Lower Threshold Success")
        EndIf
        Local $settext = ControlSetText($wincurvefitting,"","Edit4",$iUpperThreshold)
        if ($settext == 0) Then
            FileWriteLine($file,"Error: Set Upper Threshold Fail")
        Else
            FileWriteLine($file,"Set upper Threshold Success")
        EndIf

        If $iOperation == 2 OR $iOperation == 3 Then
        Else
            Local $settext1 = ControlSetText($wincurvefitting,"","Edit5",$iMinEllipseRadius)
            If ($settext1 == 0) Then
                FileWriteLine($file,"Error: Set Min Ellipse Radius Fail")
            Else
                FileWriteLine($file,"Set Min Ellipse Radius Success")
            EndIf
        EndIf

    Local $strOk = ControlClick($wincurvefitting,"","Button7")
    If $strOk == 0 Then
        FileWriteLine($file, 'Error: Click Button7 Fail')
    Else
        FileWriteLine($file, 'Button7: Click OK Success')
    EndIf
    sleep($iSleepTime)
    

    If $reset == 0 Then
        ControlClick($wincurvefitting,"","Button6")
        sleep($iSleepTime)
        $ctrlClk4 = ControlClick("WINAPP","",59398,"left",1,$iXClickFile,$iYClickFile)
        If $ctrlClk4 == 0 Then
            FileWriteLine($file,"Controlclick file failure")
        Else
            FileWriteLine($file,"Controlclick file success")
            sleep($iSleepTime)
            $ctrlClk5 = ControlClick("WINAPP","",59398,"left",1,$iXClickSaveAs,$iYClickSaveAs)
            If $ctrlClk5 == 0 Then
                FileWriteLine($file,"ControlClick Save failure ")
            Else
                FileWriteLine($file,"Controlclick Save Success")
                Local $winsave = WinWait("Save As","")
                        if $winsave == 0 Then
                       FileWriteLine($file, "Control-SaveAs: Cannot Open Save Window")
                        Else
            WinActivate($winsave)
            FileWriteLine($file, "Control-SaveAs: Open Save Window ")
            if($iType == 0) Then
                $strType = '_EllipseFit.bmp'
            ElseIf($iType == 1)Then
                $strType = '_CircleFit.bmp'
            ElseIf($iType == 2)Then
                $strType = '_2nd order.bmp'
            ElseIf($iType == 3)Then
                $strType = '_3rd order.bmp'
            EndIf
            $strSavePath = $strOut&$strType
            Local $strSave = ControlSetText("Save As", "","Edit1",$strSavePath)
            Sleep($iSleepTime)
            if ($strSave == 0) Then
                FileWriteLine($file, 'Error:SaveAs Fail-Cannot Save Image')
            Else
                FileWriteLine($file, 'Save Image success')
                ;ControlClick($winsave,"","Button1") ; Button2 for XP
                ControlClick("SaveAs","",Send("!s"))
                sleep($iSleepTime)
                $winText = ControlGetText("[Active]","","[ID:65280]")
                $OutImageName = 'Saving Image: '& $winText
                FileWriteLine($file,$outImageName)
                Sleep($iSleepTime)
                $winHandle2 = ControlGetHandle("[Active]","","[ID:65280]")
                if @error == 1 Then
                    FileWriteLine($file,"Error: Cannot get Handle of the output Image")
                Else
                    FileWritELine($file,"Get handle of output image is success")
                EndIf
            EndIf
            WinClose($winHandle2)
            sleep($iSleepTime)
            ControlClick($wincurvefitting,"","Button6")
            sleep($iSleepTime)
            WinClose($winHandle1)
        EndIf
    EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Sonali,

Why did you open a second thread? Fast fingers?

Now you have 3 threads opened within 7 minutes.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Now you have 3 threads opened within 7 minutes.

4 threads in 12mins.


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Even better ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Even better ;)

:doh: sorry not out of intensions

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

sonali,

The occasional double thread I can understand, but posting the same thread 5 times is completely OTT.  I have deleted all the other threads - do NOT open any more. :naughty:

M23

Edit:  I see you have apologised - that is an end of the matter. :)

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

sonali,

The occasional double thread I can understand, but posting the same thread 5 times is completely OTT.  I have deleted all the other threads - do NOT open any more. :naughty:

M23

Edit:  I see you have apologised - that is an end of the matter. :)

My internet was slow and multiple times i tried thinking that it has not got uploaded.from next time i will be careful:(

Share this post


Link to post
Share on other sites

Put a "Whle  ... Wend" loop into your script until your file exists.

Put a "Sleep" into your "While" loop if you want less CPU used.

Share this post


Link to post
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
Sign in to follow this  
Followers 0