aa2zz6 Posted February 19, 2017 Share Posted February 19, 2017 (edited) I'm trying to scan an INI file for a certain word but I'm not sure how to parse through text for "No Match". If it's not found then loop until pixel orientation changes in $ListFile2. INI File looks like this: Examine filled [Scanner] IGNORE_ERRORS=0 1=0F0D07 116:805 Match 2=222222 117:806 Match 3=261D1D 118:807 Match 4=777F8D 119:808 Match 5=839EB5 120:809 Match 6=766D53 121:810 Match 7=7B6339 122:811 Match 8=7F673D 123:812 Match Code #include <MsgBoxConstants.au3> read() Func read() Local Const $hostfile = @ScriptDir & "\" & "Final_List.ini" $Readvar = IniReadSection($hostfile, "Scanner") ;---------------------------------------------------------------------------------------- ; Read ini ;---------------------------------------------------------------------------------------- If Not @error Then For $number = 2 To $Readvar[0][0] If $Readvar[$number][1] == "No Match" Then Global $DisplayNumber = $Readvar[$number][0] Global $DisplayName = $Readvar[$number][1] MsgBox($MB_SYSTEMMODAL, "Results", "Found a match.", 1) Else MsgBox($MB_SYSTEMMODAL, "Results", "Match not found.", 1) ;ExitLoop EndIf Next EndIf EndFunc ;==>read Updated: selective words changed in first. New help question on read() function below.. Edited February 20, 2017 by aa2zz6 Noted: Selective words are cancer Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 19, 2017 Moderators Share Posted February 19, 2017 (edited) aa2zz6, You have been a member here long enough to know that we frown on anything to do with gaming and yet you post an script which might as well have a large red "GAME" flag attached to it while sounding a very loud hooter to attract even more attention. So, as the basis to the question has nothing to do with gaming as such, I suggest you do 2 things: Rewrite the script above to use more neutral terms. Engage your brain before posting in future. All clear? M23 Edited February 19, 2017 by Melba23 Fixed formatting Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
aa2zz6 Posted February 19, 2017 Author Share Posted February 19, 2017 Yeah I'm not looking to do game automation script. I manly lean towards automating scripts to help ease my mundane mapping choirs. So I figured it's easier to use simple terms rather than something that makes no sense. Link to comment Share on other sites More sharing options...
Subz Posted February 19, 2017 Share Posted February 19, 2017 (edited) #include <Array.au3> #include <MsgBoxConstants.au3> Global $aDisplay[0][2] MsgBox($MB_SYSTEMMODAL, 'Results', 'Found ' & read("Search") & ' Matches.') _ArrayDisplay($aDisplay) Func read($sSearch) Local Const $hostfile = @ScriptDir & "\" & "Final_List.ini" Local $iCount = 0 $Readvar = IniReadSection($hostfile, "Scanner") ;---------------------------------------------------------------------------------------- ; Read ini ;---------------------------------------------------------------------------------------- If Not @error Then For $i = 2 To $Readvar[0][0] If StringInStr($Readvar[$i][1], $sSearch) Then _ArrayAdd($aDisplay, $Readvar[$i][0] & '|' & $Readvar[$i][1]) $iCount += 1 MsgBox($MB_SYSTEMMODAL, "Results", "Found a match.", 1) Else MsgBox($MB_SYSTEMMODAL, "Results", "Match not found.", 1) ;ExitLoop EndIf Next Return $iCount EndIf Return $iCount EndFunc ;==>read Edited February 19, 2017 by Subz aa2zz6 1 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 19, 2017 Moderators Share Posted February 19, 2017 aa2zz6, Quote I figured it's easier to use simple terms rather than something that makes no sense And I entirely agree with this sentiment. But please choose terms which are not so game-related in future - could I suggest that using the names of fruit or cartoon characters would be less likely to attract attention. M23 aa2zz6 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Subz Posted February 19, 2017 Share Posted February 19, 2017 Updated the script above, as $DisplayNumber and $DisplayName would have only returned the last matched items. Link to comment Share on other sites More sharing options...
aa2zz6 Posted February 20, 2017 Author Share Posted February 20, 2017 (edited) How is the read() function being called? I think once the processing tool initials I'll have to use _2ndPixelScan and read() function to loop until the pixel orientation of "Writing Features 1" changes pixel orientation to "Completed". I'll need to include a filedelete for _2ndpixelscan so it compares against 1stpixelscan and read() function will detect change and move to the next processing tool. expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <File.au3> Opt('PixelCoordMode', 1) Global $ListFile1 = @ScriptDir & '\List_1.ini' Global $Ignore = 'IGNORE_ERRORS=' & IniWrite($ListFile1, "Scanner", "IGNORE_ERRORS", 0) Global $ListFile2 = @ScriptDir & '\List_2.ini' Global $Ignore = 'IGNORE_ERRORS=' & IniWrite($ListFile2, "Settings", "IGNORE_ERRORS", 0) If $CmdLine[0] = 1 Then $ListFile1 = $CmdLine[1] If $CmdLine[0] = 1 Then $ListFile2 = $CmdLine[1] ;First pixel scan: _1stPixelScan(115, 804, 479, 829) ;topleft x, topleft y, bottomright x, bottomright y ;Second pixel scan: _2ndPixelScan(115, 804, 479, 829) ;topleft x, topleft y, bottomright x, bottomright y ;Compares $ListFile1() and $ListFile2 Final_List() MsgBox($MB_SYSTEMMODAL, 'Results', 'Found ' & read("No Match") & ' Matches', 1) ; ---------------------------------------------------------------------------- ; Script Function: Sets ArcGIS Desktop 10.2 window as active ; ---------------------------------------------------------------------------- Func ActiveWindow() $hWnd1 = WinGetHandle("[CLASS:]") If IsHWnd($hWnd1) Then WinActivate($hWnd1) EndIf EndFunc ;==>ActiveWindow ; ---------------------------------------------------------------------------- ; Script Function: Scans Pixel location & color ; ---------------------------------------------------------------------------- Func _1stPixelScan($left, $top, $right, $bottom) ActiveWindow() $PixelCount = Abs($left - $right) + Abs($top - $bottom) Dim $aPixelMap[$PixelCount + 1][3] $aPixelMap[$PixelCount][0] = UBound($aPixelMap) ConsoleWrite('Total number of pixels to check: ' & $aPixelMap[$PixelCount][0] & @LF) For $i = 1 To $aPixelMap[$PixelCount][0] - 1 $x = $left + $i $y = $top + $i $aPixelMap[$i][0] = Hex(PixelGetColor($x, $y), 6) $aPixelMap[$i][1] = $x $aPixelMap[$i][2] = $y $num = $i ConsoleWrite('Pixel at: ' & $aPixelMap[$i][1] & ',' & $aPixelMap[$i][2] & ' has color ' & $aPixelMap[$i][0] & @LF) FileWrite($ListFile1, $num & '=' & $aPixelMap[$i][0] & " " & $aPixelMap[$i][1] & ":" & $aPixelMap[$i][2] & @CRLF) Next EndFunc ;==>_1stPixelScan Func _2ndPixelScan($left, $top, $right, $bottom) ActiveWindow() $PixelCount = Abs($left - $right) + Abs($top - $bottom) Dim $aPixelMap[$PixelCount + 1][3] $aPixelMap[$PixelCount][0] = UBound($aPixelMap) ConsoleWrite('Total number of pixels to check: ' & $aPixelMap[$PixelCount][0] & @LF) For $i = 1 To $aPixelMap[$PixelCount][0] - 1 $x = $left + $i $y = $top + $i $aPixelMap[$i][0] = Hex(PixelGetColor($x, $y), 6) $aPixelMap[$i][1] = $x $aPixelMap[$i][2] = $y ConsoleWrite('Pixel at: ' & $aPixelMap[$i][1] & ',' & $aPixelMap[$i][2] & ' has color ' & $aPixelMap[$i][0] & @LF) $num = $i FileWrite($ListFile2, $num & '=' & $aPixelMap[$i][0] & " " & $aPixelMap[$i][1] & ":" & $aPixelMap[$i][2] & @CRLF) Next EndFunc ;==>_2ndPixelScan ; ---------------------------------------------------------------------------- ; Script Function: [Compare List_1 And List_2] = Final_List ; ---------------------------------------------------------------------------- Func Final_List() Dim $array1 Dim $array2 _FileReadToArray("List_1.ini", $array1) _FileReadToArray("List_2.ini", $array2) ; ---------------------------------------------------------------------------- ; Script Function: Compare List_1 to List_2 ; ---------------------------------------------------------------------------- For $x = 3 To $array1[0] If $x <= $array2[0] Then If $array1[$x] = $array2[$x] Then $array1[$x] &= " Match" Else $array1[$x] &= " No Match" EndIf Else ExitLoop EndIf Next _FileWriteFromArray("Final_List.ini", $array1, 1) EndFunc ;==>Final_List ;---------------------------------------------------------------------------------------- ; Read ini to figure out if process tool has completed ;---------------------------------------------------------------------------------------- Func read($sSearch) Local Const $hostfile = @ScriptDir & "\" & "Final_List.ini" Local $i = 0 $Readvar = IniReadSection($hostfile, "Scanner") Local $numberofitems = 0 If Not @error Then For $number = 1 To $Readvar[0][0] If StringInStr($Readvar[$number][1], $sSearch) Then $i += 1 ;MsgBox($MB_SYSTEMMODAL, "Results", "Found a match.", 1) Else ;MsgBox($MB_SYSTEMMODAL, "Results", "Match not found.", 1) ;ExitLoop EndIf Next Return $i EndIf Return 0 EndFunc ;==>read Edited February 20, 2017 by aa2zz6 Link to comment Share on other sites More sharing options...
Subz Posted February 20, 2017 Share Posted February 20, 2017 You could just another parameter for section name for example Func Read($sSearch, $sSection) and then call it using Read('something', 'Scanner') and then another Read('something', 'Scanner2'). I'm not sure if that's what you meant? Link to comment Share on other sites More sharing options...
aa2zz6 Posted February 20, 2017 Author Share Posted February 20, 2017 Something like this but I'm not sure how to call the read() function. I tried read($search) but it's being called before it happens and I think i'll need to research how to calculate overall rows verses No match again Match to determine percentage. Do FileDelete($ListFile2) FileDelete($Final_List) _2ndPixelScan(115, 804, 479, 829) Final_List() until read("Match") > 100% Link to comment Share on other sites More sharing options...
Subz Posted February 20, 2017 Share Posted February 20, 2017 Sorry I don't follow? Can you re-explain? Here is what I gather from your posts, but not sure if its correct and what you want to have happen? a. You create List_1.ini using _1stPixelScan function nb: Not sure why you use 2ndPixelScan function as it's exactly the same as _1stPixelScan function, you just need to add a parameter for the filename. b. You create List_2.ini using _2ndPixelScan function c. You compare the two files using Final_List function d. You want to show the matches only? Link to comment Share on other sites More sharing options...
aa2zz6 Posted February 20, 2017 Author Share Posted February 20, 2017 (edited) My previous scripts used a sleep function but depending on how big the data was being processed and which analysis tools was being used would varied on time completion. So needless to say it didn't work properly. So the goal was to find or create a pixel scanner to scan the general words on the analysis tools, such as "Writing Features 1" and would repeat until the process is done and will say "Complete". How I figured the script would have to be to work. So I figured the first pixel scan would collect the pixel color along with the coordinates and stores the information in a file called List_1 _1stPixelScan(115, 804, 479, 829) function to collect the pixel color and coordinates within the set boundaries specified. At this point I wasn't sure how to re scan the area to know if the text changed so I made another scan function and stores the information in a file called List_2 _2ndPixelScan(115, 804, 479, 829) ;topleft x, topleft y, bottomright x, bottomright y I applied a function that Compared the (2) List_1 and List_2 files and determined if they had a "Matched" or "No match" at the end. The function creates a new file called Final_List.ini and stores the "Match" and "No Match" for each one. See below: Final_List.ini looks like this.. [Scanner] IGNORE_ERRORS=0 1=4A80BE 116:805 No Match 2=F0F4F9 117:806 Match Func Final_List() Dim $array1 Dim $array2 _FileReadToArray("List_1.ini", $array1) _FileReadToArray("List_2.ini", $array2) #cs ---------------------------------------------------------------------------- Script Function: Compare List_1 to List_2 #ce ---------------------------------------------------------------------------- For $x = 3 To $array1[0] If $x <= $array2[0] Then If $array1[$x] = $array2[$x] Then $array1[$x] &= " Match" Else $array1[$x] &= " No Match" EndIf Else ExitLoop EndIf Next _FileWriteFromArray("Final_List.ini", $array1, 1) EndFunc ;==>Final_List After the Final_List.ini file is created the read function would parse through and determine whether everything looks the same or has changed. I would imagine a while loop would need to be present for it to scan until it changes and apply a continue loop to the next function which will use the same principle. My apologies if things can be completed in a more simpler way. I'm a slow learner Edited February 20, 2017 by aa2zz6 Link to comment Share on other sites More sharing options...
Subz Posted February 20, 2017 Share Posted February 20, 2017 I'm not sure but you may need to do the PixelScan for List_File1 again during the loop otherwise it would just continue looping expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <File.au3> Opt('PixelCoordMode', 1) Global $sFinalList = @ScriptDir & '\Final_List.ini' Global $sListFile1 = @ScriptDir & '\List_1.ini' FileDelete($sListFile1) IniWrite($sListFile1, "Scanner", "IGNORE_ERRORS", 0) Global $sListFile2 = @ScriptDir & '\List_2.ini' FileDelete($sListFile2) If $CmdLine[0] = 1 Then $ListFile1 = $CmdLine[1] If $CmdLine[0] = 1 Then $ListFile2 = $CmdLine[1] ;First pixel scan: _PixelScan($sListFile1, 'Scanner', 115, 804, 479, 829) ;IniFile, topleft x, topleft y, bottomright x, bottomright y While 1 IniWrite($sListFile2, "Settings", "IGNORE_ERRORS", 0) ;Second pixel scan: _PixelScan($sListFile2, 'Settings', 115, 804, 479, 829) ;IniFile, topleft x, topleft y, bottomright x, bottomright y ;Compares $ListFile1() and $ListFile2 Final_List() Read('No Match') If @error <> 0 Then FileDelete($sFinalList) FileDelete($sListFile2) ContinueLoop Else ExitLoop EndIf WEnd MsgBox($MB_SYSTEMMODAL, 'Results', 'Found ' & read("No Match") & ' Matches', 1) ; ---------------------------------------------------------------------------- ; Script Function: Sets ArcGIS Desktop 10.2 window as active ; ---------------------------------------------------------------------------- Func ActiveWindow() $hWnd1 = WinGetHandle("[CLASS:]") If IsHWnd($hWnd1) Then WinActivate($hWnd1) EndIf EndFunc ;==>ActiveWindow ; ---------------------------------------------------------------------------- ; Script Function: Scans Pixel location & color ; ---------------------------------------------------------------------------- Func _PixelScan($sListFile, $sSection, $left, $top, $right, $bottom) ActiveWindow() $PixelCount = Abs($left - $right) + Abs($top - $bottom) Dim $aPixelMap[$PixelCount + 1][3] $aPixelMap[$PixelCount][0] = UBound($aPixelMap) ConsoleWrite('Total number of pixels to check: ' & $aPixelMap[$PixelCount][0] & @LF) For $i = 1 To $aPixelMap[$PixelCount][0] - 1 $x = $left + $i $y = $top + $i $aPixelMap[$i][0] = Hex(PixelGetColor($x, $y), 6) $aPixelMap[$i][1] = $x $aPixelMap[$i][2] = $y $num = $i ; ConsoleWrite('Pixel at: ' & $aPixelMap[$i][1] & ',' & $aPixelMap[$i][2] & ' has color ' & $aPixelMap[$i][0] & @LF) IniWrite($sListFile, $sSection, $i, $aPixelMap[$i][0] & " " & $aPixelMap[$i][1] & ":" & $aPixelMap[$i][2]) Next EndFunc ;==>_1stPixelScan ; ---------------------------------------------------------------------------- ; Script Function: [Compare List_1 And List_2] = Final_List ; ---------------------------------------------------------------------------- Func Final_List() Local $aListFile1 = IniReadSection($sListFile1, 'Scanner') Local $aListFile2 = IniReadSection($sListFile2, 'Settings') Local $iListFile If $aListFile1[0][0] = $aListFile2[0][0] Then ConsoleWrite('$aListFile1 Row Size = $aListFile2 Row Size' & @CRLF) $iListFile = $aListFile1[0][0] ElseIf $aListFile1[0][0] > $aListFile2[0][0] Then ConsoleWrite('$aListFile1 Row Size > $aListFile2 Row Size' & @CRLF) $iListFile = $aListFile1[0][0] Else ConsoleWrite('$aListFile1 Row Size < $aListFile2 Row Size' & @CRLF) $iListFile = $aListFile2[0][0] EndIf ; ---------------------------------------------------------------------------- ; Script Function: Compare List_1 to List_2 ; ---------------------------------------------------------------------------- For $i = 2 To $iListFile If $aListFile1[$i][1] = $aListFile2[$i][1] Then IniWrite($sFinalList, 'Scanner', $i, $aListFile1[$i][1] & " Match") Else IniWrite($sFinalList, 'Scanner', $i, $aListFile1[$i][1] & " No Match") EndIf Next EndFunc ;==>Final_List ;---------------------------------------------------------------------------------------- ; Read ini to figure out if process tool has completed ;---------------------------------------------------------------------------------------- Func read($sSearch = 'No Match') Local $i = 0 $Readvar = IniReadSection($sFinalList, "Scanner") If Not @error Then For $number = 1 To $Readvar[0][0] If StringInStr($Readvar[$number][1], $sSearch) Then Return SetError(1, 0, False) Else $i += 1 EndIf Next Return SetError(0, 0, $i) EndIf Return SetError(-1, 0, False) EndFunc ;==>read 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