Sign in to follow this  
Followers 0
dufran3

Script efficiency help

1 post in this topic

with the help of some users on here, I have this script, that works great. I'm curious if it is as efficient as it can be. Before you ask, I HAVE to use mouse click, as it is interacting with a java application, and I cannot read any control or window data from it. As far as everything else is concerned, is there anywhere that I can improve my logic?

; #INDEX# =======================================================================================================================
; Title .........: Portal Procedure Batch Printer for CGS
; AutoIt Version : 3.2
; Language ......: English
; Description ...: Batch Printer for Portal program at CGS. Only containts procedures managed at satellite location.
; Author(s) .....: ME!
; ===============================================================================================================================

#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <ColorConstants.au3>

Opt('MouseCoordMode', 0)
Opt('PixelCoordMode', 0)
Opt('GUIOnEventMode', 1)

HotKeySet("{ESC}", "_OnExit")

;Create Array
#region
Dim $aProcedure [112][3] = [ _
        ['1.3.9', 'PPM', 'PPI'], _
        ['1.3.10A', 'PPM', 'PPI'], _
        ['1.3.10B', 'PPM', 'PPI'], _
        ['1.3.10C', 'PPM', 'PPI'], _
        ['1.3.27', 'PPM', 'PPI'], _
        ['1.3.30', 'PPM', 'PPI'], _
        ['1.3.51', 'PPM', 'PPI'], _
        ['1.3.56', 'PPM', 'PPI'], _
        ['1.3.57', 'PPM', 'PPI'], _
        ['1.3.62', 'PPM', 'PPI'], _
        ['1.3.64', 'PPM', 'PPI'], _
        ['1.3.68', 'PPM', 'PPI'], _
        ['1.3.69', 'PPM', 'PPI'], _
        ['1.3.76', 'PPM', 'PPI'], _
        ['1.4.7', 'PPM', 'PPI'], _
        ['1.20.1', 'PPM', 'PPI'], _
        ['10.1.13', 'PPM', 'PPI'], _
        ['10.1.21', 'PPM', 'PPI'], _
        ['10.1.22', 'PPM', 'PPI'], _
        ['10.2.7', 'PPM', 'PPI'], _
        ['10.2.10', 'PPM', 'PPI'], _
        ['10.2.13', 'PPM', 'PPI'], _
        ['10.2.14', 'PPM', 'PPI'], _
        ['10.2.17', 'PPM', 'PPI'], _
        ['10.2.18', 'PPM', 'PPI'], _
        ['10.2.23', 'PPM', 'PPI'], _
        ['10.2.27', 'PPM', 'PPI'], _
        ['10.2.28', 'PPM', 'PPI'], _
        ['10.2.29', 'PPM', 'PPI'], _
        ['10.2.31', 'PPM', 'PPI'], _
        ['10.2.33', 'PPM', 'PPI'], _
        ['10.2.34', 'PPM', 'PPI'], _
        ['10.2.37', 'PPM', 'PPI'], _
        ['10.2.41', 'PPM', 'PPI'], _
        ['10.2.47', 'PPM', 'PPI'], _
        ['10.2.51', 'PPM', 'PPI'], _
        ['10.2.53', 'PPM', 'PPI'], _
        ['10.2.79', 'PPM', 'PPI'], _
        ['10.2.101', 'PPM', 'PPI'], _
        ['10.4.1', 'PPM', 'PPI'], _
        ['10.4.2', 'PPM', 'PPI'], _
        ['10.4.3', 'PPM', 'PPI'], _
        ['10.4.4', 'PPM', 'PPI'], _
        ['10.4.10', 'PPM', 'PPI'], _
        ['10.4.11', 'PPM', 'PPI'], _
        ['10.4.12', 'PPM', 'PPI'], _
        ['10.4.14', 'PPM', 'PPI'], _
        ['10.23.1', 'PPM', 'PPI'], _
        ['10.23.2', 'PPM', 'PPI'], _
        ['10.23.4', 'PPM', 'PPI'], _
        ['10.24.12', 'PPM', 'PPI'], _
        ['10.24.135', 'PPM', 'PPI'], _
        ['10.25.19', 'PPM', 'PPI'], _
        ['10.25.46', 'PPM', 'PPI'], _
        ['10.25.54', 'PPM', 'PPI'], _
        ['10.25.55', 'PPM', 'PPI'], _
        ['10.25.57', 'PPM', 'PPI'], _
        ['10.25.61', 'PPM', 'PPI'], _
        ['10.25.78', 'PPM', 'PPI'], _
        ['11.2.11.3', 'PPM', 'PPI'], _
        ['11.2.15.7', 'PPM', 'PPI'], _
        ['11.2.23.4', 'PPM', 'PPI'], _
        ['CIVES-5', 'ENG', 'PPI'], _
        ['CIVES-6', 'ENG', 'PPI'], _
        ['DES-2-1', 'ENG', 'PPI'], _
        ['DES-2-2', 'ENG', 'PPI'], _
        ['DES-2-7', 'ENG', 'PPI'], _
        ['DES-3-1', 'ENG', 'PPI'], _
        ['DES-3-2', 'ENG', 'PPI'], _
        ['DES-3-3', 'ENG', 'PPI'], _
        ['DES-4-1', 'ENG', 'PPI'], _
        ['DES-4-2', 'ENG', 'PPI'], _
        ['DES-4-12', 'ENG', 'PPI'], _
        ['DES-5-2', 'ENG', 'PPI'], _
        ['EMS-01', 'EMS', 'MAN'], _
        ['ENG-DES-02', 'ENG', 'PPI'], _
        ['GEN-RPP-04', 'PPM', 'PPI'], _
        ['GEN-RPP-10', 'PPM', 'PPI'], _
        ['HPI-0.19', 'HPI', 'PPI'], _
        ['ISPM-1', 'ISPM', 'PPI'], _
        ['ISPM-2', 'ISPM', 'PPI'], _
        ['ISPM-3', 'ISPM', 'PPI'], _
        ['ISPM-4', 'ISPM', 'PPI'], _
        ['ISPM-5', 'ISPM', 'PPI'], _
        ['ISPM-6', 'ISPM', 'PPI'], _
        ['ISPM-7', 'ISPM', 'PPI'], _
        ['ISPM-8', 'ISPM', 'PPI'], _
        ['ISPM-9', 'ISPM', 'PPI'], _
        ['ISPM-10', 'ISPM', 'PPI'], _
        ['ISPM-11', 'ISPM', 'PPI'], _
        ['ISPM-12', 'ISPM', 'PPI'], _
        ['ISPM-13', 'ISPM', 'PPI'], _
        ['ISPM-14', 'ISPM', 'PPI'], _
        ['ISPM-15', 'ISPM', 'PPI'], _
        ['ISPM-16', 'ISPM', 'PPI'], _
        ['ISPM-17', 'ISPM', 'PPI'], _
        ['ISPM-18', 'ISPM', 'PPI'], _
        ['ISPM-19', 'ISPM', 'PPI'], _
        ['ISPM-20', 'ISPM', 'PPI'], _
        ['MI-2.6.1', 'MAI', 'PPI'], _
        ['MWP-1', 'MWP', 'MAN'], _
        ['MWP-5', 'MWP', 'MAN'], _
        ['MWP-7', 'MWP', 'MAN'], _
        ['MWP-10', 'MWP', 'MAN'], _
        ['MWP-13', 'MWP', 'MAN'], _
        ['QCI-2', 'QCI', 'PPI'], _
        ['SWP-CHE-05', 'SWP', 'PPI'], _
        ['SWP-CM-01', 'SWP', 'PPI'], _
        ['SWP-DES-01', 'SWP', 'PPI'], _
        ['SWP-OSH-06', 'SWP', 'PPI'], _
        ['SWP-OSH-08', 'SWP', 'PPI'], _
        ['SWP-TST-01', 'SWP', 'PPI'] _
        ]
#endregion

Dim $aProcedureSize = UBound($aProcedure)
;Set Extended Styles
Local $exStyles = BitOR($LVS_EX_FULLROWSELECT,$LVS_EX_CHECKBOXES,$LVS_EX_GRIDLINES)
;Create GUI
$hWnd = GUICreate('Portal Batch Procedure Printer', 400, 500)
;Create Buttons
$bPrint = GUICtrlCreateButton('Print',325,50,60)
$bExit = GUICtrlCreateButton('Exit', 325, 90, 60)
;Create Button Events
GUICtrlSetonEvent($bExit, '_OnExit')
GUICtrlSetOnEvent($bPrint, '_Print')
;Create List View and Apply Styles
$hListView = GUICtrlCreateListView('', 2, 2, 294, 468)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $exStyles)
; Add columns
_GUICtrlListView_AddColumn($hListView, 'Doc Type', 70)
_GUICtrlListView_AddColumn($hListView, 'Sub Type', 70)
_GUICtrlListView_AddColumn($hListView, 'Doc No.', 134)
; Set colors
_GUICtrlListView_SetBkColor($hListView, $CLR_MONEYGREEN)
_GUICtrlListView_SetTextColor($hListView, $CLR_BLACK)
_GUICtrlListView_SetTextBkColor($hListView, $CLR_MONEYGREEN)
;Add items and subitems to list view
For $i = 0 to $aProcedureSize -1
    _GUICtrlListView_AddItem($hListView,$aProcedure[$i][2], 0)
    _GUICtrlListView_AddSubItem($hListView, $i,$aProcedure[$i][1], 1)
    _GUICtrlListView_AddSubItem($hListView, $i, $aProcedure[$i][0], 2)
Next
;Set GUI Close Event
GUISetOnEvent($GUI_EVENT_CLOSE, '_OnExit')
;Display GUI
GUISetState()

While 1
    Sleep(1000)
WEnd

Func _Print() ;<====Print Function Start
GUISetState(@SW_HIDE)
    For $i = 0 to $aProcedureSize -1
        If _GUICtrlListView_GetItemChecked($hListView, $i) Then
            WinActivate('TIM')
            $PortalWait = WinWaitActive('TIM','',10)
                If $PortalWait == 0 Then
                    MsgBox(0,'Error','Portal window not found')
                    GuiSetState(@SW_SHOW)
                    Return
                EndIf
            MouseClick('Left',378,75)
            WinWait('TIMX000 - VENTYX INCORPORATED - [ PAS6 ]')
            MouseClick('Left',461,432)
            WinWait ('TIMMENU - [ PAS6 ]')
            MouseClick('Left',211,110)
            WinWait('TIMC010 - CONT DOC - INFORMATION - [ PAS6 ]')
            MouseClick('Left',119,151)
            Send($aProcedure[$i][2])
            MouseClick('Left',440,151)
            Send($aProcedure[$i][1])
            MouseClick('Left',200,174)
            Send($aProcedure[$i][0])
            Send('{ENTER}')
            ;Check to see if image has loaded
            $ImageColorHex = Hex(PixelGetColor(376,533))
                Do
                    $ImageColorHex = Hex(PixelGetColor(376,533))
                Until $ImageColorHex == '0000FFFF' 
            MouseClick('Left',376,533)
            ;IE Download Window
            WinWait('File Download')
            WinActivate('FileDownload')
            Sleep(500)
            ControlClick('File Download', '', '[ID:4423]')
            ;Adobe Reader Window
            WinWaitActive('00')
            Sleep(1000)
            Send('!{F4}') ;<-- Don't forget to remove after done testing
            #CS
            ;Adobe
            WinActivate('00')
            WinWaitActive('00')
            Send('^p')
            ;Printing
            WinWaitActive('Print')
            ControlClick('Print','','Button27')
            WinWait('Progress')
            WinWaitClose('Progress')
            WinActivate('00')
            Sleep(1000)
            Send('!{F4}')
            #CE
        EndIf
    Next
    MsgBox(0,'','Script is finished')
    Exit
EndFunc ;<====Print Function End

Func _OnExit() ; <====Exit Function Start
    Exit
EndFunc; <====Exit Function End

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