aa2zz6 Posted January 29, 2017 Share Posted January 29, 2017 I'm trying to setup this script to read a text file that'll list a series True or False in order for certain scripts to run for ArcGIS Desktop. The problem I'm having is the main script that reads the log file is getting stuck on the first If statement StringintStr. The idea was to have a main script read a text file and whether it says true or false would determine which map function to execute expandcollapse popup#include <File.au3> #include <Array.au3> Local Const $Map_Settings = @ScriptDir & '\Map Settings.log' ;log file Local Const $sFilePath = @ScriptDir & '\Directories\Log Sheet.log' Global $True = "True" Global $False = "False" Global $equal = "=" Global $Monitor = "Monitor" Global $ArcGIS = "ArcGIS" $handle_read = FileOpen($Map_Settings) While 1 ; read each line from a file $line_read = FileReadLine($handle_read) ; exit the loop if end of file If @error Then ExitLoop If StringInStr($line_read, $Monitor & $equal & $True) Then ;MsgBox(0, "Result", $Monitor & $equal & $True, 1) RunWait(@AutoItExe & ' "' & @ScriptDir & '\Directories\Scripts\[0] Monitor Log\Monitor.exe"') _FileWriteToLine($sFilePath, 1, "" & $Monitor & $equal & $True, True) ExitLoop EndIf ;Open ArcGIS Explorer If StringInStr($line_read, $ArcGIS & $equal & $True) Then ;MsgBox(0, "Result", $ArcGIS & $equal & $True, 1) RunWait(@AutoItExe & ' "' & @ScriptDir & '\E3.exe"') _FileWriteToLine($sFilePath, 1, "" & $ArcGIS & $equal & $True, True) ExitLoop EndIf WEnd Link to comment Share on other sites More sharing options...
Subz Posted January 29, 2017 Share Posted January 29, 2017 I think it's just reading the first line of the log, you could place a ConsoleWrite($line_read & @crlf) to debug. Personally I would use FileReadToArray or use a variable in your loop to step up for example: $i = 1 While 1 ; read each line from a file $line_read = FileReadLine($handle_read, $i) ; exit the loop if end of file If @error Then ExitLoop If StringInStr($line_read, $Monitor & $equal & $True) Then ;MsgBox(0, "Result", $Monitor & $equal & $True, 1) RunWait(@AutoItExe & ' "' & @ScriptDir & '\Directories\Scripts\[0] Monitor Log\Monitor.exe"') _FileWriteToLine($sFilePath, 1, "" & $Monitor & $equal & $True, True) ExitLoop EndIf ;Open ArcGIS Explorer If StringInStr($line_read, $ArcGIS & $equal & $True) Then ;MsgBox(0, "Result", $ArcGIS & $equal & $True, 1) RunWait(@AutoItExe & ' "' & @ScriptDir & '\E3.exe"') _FileWriteToLine($sFilePath, 1, "" & $ArcGIS & $equal & $True, True) ExitLoop EndIf $i += 1 WEnd Link to comment Share on other sites More sharing options...
aa2zz6 Posted January 29, 2017 Author Share Posted January 29, 2017 (edited) I'm trying to use the FileReadToArray but I don't get any return results or errors. #include <file.au3> Global $True = "True" Global $False = "False" Global $equal = "=" Global $Monitor = "Monitor" Global $vReturn Global $handle_read _read() Func _read() Local Const $sFilePath = @ScriptDir & '\Map Settings.log' _FileReadToArray($sFilePath, $vReturn) $handle_read = FileOpen($sFilePath) If @error Then MsgBox(4096, "Error", "Unable to read") Else For $i = 1 To $vReturn[1] If $i[$vReturn][1] == "test" Then MsgBox($MB_SYSTEMMODAL, "Map", "Preview ", 5) ExitLoop ; Exits For - Next loop (stops) when search value, "", is found? EndIf Next EndIf EndFunc ;==>_read Edited January 29, 2017 by aa2zz6 Link to comment Share on other sites More sharing options...
Subz Posted January 29, 2017 Share Posted January 29, 2017 Try this: #include <file.au3> Global $True = "True" Global $False = "False" Global $equal = "=" Global $Monitor = "Monitor" Global $vReturn Global $handle_read _read() Func _read() Local $sFilePath = @ScriptDir & '\Map Settings.log' _FileReadToArray($sFilePath, $vReturn) If @error Then MsgBox(4096, "Error", "Unable to read") Else For $i = 1 To $vReturn[0] If $vReturn[$i] == 'test' Then MsgBox($MB_SYSTEMMODAL, "Map", "Preview ", 5) ExitLoop ; Exits For - Next loop (stops) when search value, "", is found? EndIf Next EndIf EndFunc ;==>_read aa2zz6 1 Link to comment Share on other sites More sharing options...
aa2zz6 Posted January 29, 2017 Author Share Posted January 29, 2017 Thanks Subz, I appreciate the help. You mentioned above about ConsoleWrite($line_read & @crlf). How is this used for debugging? Link to comment Share on other sites More sharing options...
Subz Posted January 29, 2017 Share Posted January 29, 2017 (edited) Using your first post as an example, you can place a toggle $debug = True or False at the top of your script and then within your script add ConsoleWrite entries to see what the result of your function is. Using this example I found that I was incorrect in suggesting that it was only reading the first line, however I could then determine that you may or may not have had spaces in your search, so for example "Monitor = True" is not the same as "Monitor=True" so would have returned 0 (String was not found). By the way in your Map Settings.log do you have any [Section Names] in square brackets, if so you could just use IniRead to get those values. expandcollapse popup#include <File.au3> #include <Array.au3> Local $debug = True Local Const $Map_Settings = @ScriptDir & '\Map Settings.log' ;log file Local Const $sFilePath = @ScriptDir & '\Directories\Log Sheet.log' Global $True = "True" Global $False = "False" Global $equal = "=" Global $Monitor = "Monitor" Global $ArcGIS = "ArcGIS" $handle_read = FileOpen($Map_Settings) While 1 ; read each line from a file $line_read = FileReadLine($handle_read) ; exit the loop if end of file If @error Then ExitLoop If $debug Then ConsoleWrite('Read Line: ' & $line_read & @CRLF) If StringInStr($line_read, $Monitor & $equal & $True) Then If $debug Then ConsoleWrite('StringinStr $Monitor & $equal: ' & StringInStr($line_read, $Monitor & $equal & $True) & @CRLF) ;MsgBox(0, "Result", $Monitor & $equal & $True, 1) RunWait(@AutoItExe & ' "' & @ScriptDir & '\Directories\Scripts\[0] Monitor Log\Monitor.exe"') _FileWriteToLine($sFilePath, 1, "" & $Monitor & $equal & $True, True) ExitLoop EndIf ;Open ArcGIS Explorer If StringInStr($line_read, $ArcGIS & $equal & $True) Then ;MsgBox(0, "Result", $ArcGIS & $equal & $True, 1) RunWait(@AutoItExe & ' "' & @ScriptDir & '\E3.exe"') _FileWriteToLine($sFilePath, 1, "" & $ArcGIS & $equal & $True, True) ExitLoop EndIf WEnd PS: This only works from within Scite when using Tools » Go Edited January 29, 2017 by Subz Added PS Link to comment Share on other sites More sharing options...
careca Posted January 30, 2017 Share Posted January 30, 2017 On 1/29/2017 at 0:32 AM, aa2zz6 said: I'm trying to setup this script to read a text file that'll list a series True or False in order for certain scripts to run for ArcGIS Desktop....The idea was to have a main script read a text file and whether it says true or false would determine which map function to execute So it has to read each line and execute on that basis, right? Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
aa2zz6 Posted January 30, 2017 Author Share Posted January 30, 2017 (edited) On 1/28/2017 at 10:15 PM, Subz said: Using your first post as an example, you can place a toggle $debug = True or False at the top of your script and then within your script add ConsoleWrite entries to see what the result of your function is. Using this example I found that I was incorrect in suggesting that it was only reading the first line, however I could then determine that you may or may not have had spaces in your search, so for example "Monitor = True" is not the same as "Monitor=True" so would have returned 0 (String was not found). By the way in your Map Settings.log do you have any [Section Names] in square brackets, if so you could just use IniRead to get those values. I haven't used debugging before but I feel it's something that I'll need to learn especially while troubleshooting scripts. 17 hours ago, careca said: So it has to read each line and execute on that basis, right? Yeah that's what I've been researching and testing for the past few days. Edited January 30, 2017 by aa2zz6 Link to comment Share on other sites More sharing options...
careca Posted January 31, 2017 Share Posted January 31, 2017 (edited) If i got it wrong, please correct me, i understood that if true, so this, if false, do that, so: expandcollapse popup#include <File.au3> #include <Array.au3> Local $debug = True Local Const $Map_Settings = @ScriptDir & '\123Settings.log' Global $True = "True" Global $False = "False" Global $equal = "=" Global $Monitor = "Monitor" Global $ArcGIS = "ArcGIS" $handle_read = FileOpen($Map_Settings) While 1 ; read each line from a file $line_read = FileReadLine($handle_read) ; exit the loop if end of file If @error Then ExitLoop If $debug Then ConsoleWrite('Read Line: ' & $line_read & @CRLF) If StringInStr($line_read, $True, 2, 1) Then MsgBox(0, "Result", $Monitor & $equal & $True, 1) ;RunWait(@AutoItExe & ' "' & @ScriptDir & '\Directories\Scripts\[0] Monitor Log\Monitor.exe"') ;_FileWriteToLine($sFilePath, 1, "" & $Monitor & $equal & $True, True) ExitLoop EndIf ;Open ArcGIS Explorer If StringInStr($line_read, $False, 2, 1) Then MsgBox(0, "Result", $ArcGIS & $equal & $False, 1) ;RunWait(@AutoItExe & ' "' & @ScriptDir & '\E3.exe"') ;_FileWriteToLine($sFilePath, 1, "" & $ArcGIS & $equal & $True, True) ExitLoop EndIf WEnd I don't get why the filewriteline, it's a log, right? This way it searches No-Case words true and false and act accordingly. Mbox to show, change as appropriate. Why not have the code of E3 and monitor exes included in this script? are they yours? Edited January 31, 2017 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
aa2zz6 Posted January 31, 2017 Author Share Posted January 31, 2017 (edited) 16 hours ago, careca said: If i got it wrong, please correct me, i understood that if true, so this, if false, do that, so: I don't get why the filewriteline, it's a log, right? This way it searches No-Case words true and false and act accordingly. Mbox to show, change as appropriate. Why not have the code of E3 and monitor exes included in this script? are they yours? I tried to create a series of functions inside my script but I couldn't figure out how to assign a variable to each functions so when the script scans for Explorer=true or false inside the log file and depending on the choice it would do something. I couldn't figure out how to attach a variable to a function so I move them into there own scripts and call them. The E3.exe is a 3rd party mapping software provided by ESRI. 123Settings.log ;~ wrote inside log Explorer=True expandcollapse popup#include <File.au3> #include <Array.au3> Local $debug = True Local Const $Map_Settings = @ScriptDir & '\123Settings.log' Global $True = "True" Global $False = "False" Global $equal = "=" Global $ArcGIS = "Explorer" $handle_read = FileOpen($Map_Settings) While 1 ; read each line from a file $line_read = FileReadLine($handle_read) ; exit the loop if end of file If @error Then ExitLoop If $debug Then ConsoleWrite('Read Line: ' & $line_read & @CRLF) If StringInStr($line_read, $True, 2, 1) Then MsgBox(0, "Result", $Monitor & $equal & $True, 1) ;RunWait(@AutoItExe & ' "' & @ScriptDir & '\Directories\Scripts\[0] Monitor Log\Monitor.exe"') ;_FileWriteToLine($sFilePath, 1, "" & $Monitor & $equal & $True, True) ExitLoop EndIf ;Open ArcGIS Explorer If StringInStr($line_read, $False, 2, 1) Then MsgBox(0, "Result", $ArcGIS & $equal & $False, 1) ;RunWait(@AutoItExe & ' "' & @ScriptDir & '\E3.exe"') ;_FileWriteToLine($sFilePath, 1, "" & $ArcGIS & $equal & $True, True) ExitLoop EndIf WEnd Func ArcGIS_Explorer();How to integrate unique variable to call function if true or false ;Load Map and check settings EndFunc Edited January 31, 2017 by aa2zz6 Link to comment Share on other sites More sharing options...
Subz Posted January 31, 2017 Share Posted January 31, 2017 Can you post the log file? Link to comment Share on other sites More sharing options...
aa2zz6 Posted January 31, 2017 Author Share Posted January 31, 2017 1 minute ago, Subz said: Can you post the log file? Here's the Log file Map Settings.log Link to comment Share on other sites More sharing options...
Subz Posted January 31, 2017 Share Posted January 31, 2017 Does the log have any data above it i.e. a section name for example [something]? Link to comment Share on other sites More sharing options...
aa2zz6 Posted January 31, 2017 Author Share Posted January 31, 2017 Nope, I've been listing it like this. I think the .log file doesn't require section name like .ini files. Link to comment Share on other sites More sharing options...
Subz Posted January 31, 2017 Share Posted January 31, 2017 So then you can use something like this: Local $debug = True Global $ArcGIS = _ReadLogFile() If $ArcGIS = True Then ArcGIS_Explorer('Do something here') Func _ReadLogFile($sSearch = 'Explorer=true') Local $line_read Local $Map_Settings = @ScriptDir & '\Map Settings.log' Local $handle_read = FileOpen($Map_Settings, 0) While 1 ; read each line from a file $line_read = FileReadLine($handle_read) ; exit the loop if end of file If @error Then ExitLoop If $debug Then ConsoleWrite('Read Line: ' & $line_read & @CRLF) If StringInStr($line_read, $sSearch) Then Return True WEnd ;~ $sSearch was not found Return False EndFunc Func ArcGIS_Explorer($sMsgBox);How to integrate unique variable to call function if true or false MsgBox(0,'Explorer found in log', $sMsgBox) ;Load Map and check settings EndFunc Link to comment Share on other sites More sharing options...
aa2zz6 Posted February 1, 2017 Author Share Posted February 1, 2017 (edited) Local $debug = True Global $ArcGIS = _ReadLogFile() Global $Settings = _ReadLogFile() If $ArcGIS = True Then ArcGIS_Explorer('Do something here') If $Settings = True Then ArcGIS_Settings('Do something here') Func _ReadLogFile($sSearch = 'Explorer=true') Local $line_read Local $Map_Settings = @ScriptDir & '\Map Settings.log' Local $handle_read = FileOpen($Map_Settings, 0) While 1 ; read each line from a file $line_read = FileReadLine($handle_read) ; exit the loop if end of file If @error Then ExitLoop If $debug Then ConsoleWrite('Read Line: ' & $line_read & @CRLF) If StringInStr($line_read, $sSearch) Then Return True WEnd ;~ $sSearch was not found Return False EndFunc ;==>_ReadLogFile Func ArcGIS_Explorer($sMsgBox) MsgBox(0, 'Explorer found in log', $sMsgBox, 1) ;Load Map and check settings EndFunc ;==>ArcGIS_Explorer Func ArcGis_Settings($sMsgBox) MsgBox(0, 'Explorer found in log', $sMsgBox, 1) ;Load Map and check settings EndFunc ;==>ArcGIS_Explorer Would it be more practical to repeat the _ReadLogFile function for each one or create something that is dynamic for all function. I'm wondering whether an array to hold the different searches but somehow would reference the functions this way I won't have to list _ReadLogFile each time. Func _ReadLogFile($sSearch = 'Explorer=true') Edited February 1, 2017 by aa2zz6 Link to comment Share on other sites More sharing options...
Subz Posted February 1, 2017 Share Posted February 1, 2017 How many different searchs are you wanting to do? Can you list them? Link to comment Share on other sites More sharing options...
aa2zz6 Posted February 1, 2017 Author Share Posted February 1, 2017 Here is 6 I preform weekly. Launch map Program Check map settings and customization Clear map Cache Export map Layers for WebTMS Publish map layers to Portal Geodatabase maintenance Link to comment Share on other sites More sharing options...
Subz Posted February 1, 2017 Share Posted February 1, 2017 (edited) Sorry I meant what searches are you wanting to perform i.e. Explorer=True Settings???=... You can just use the function I created by changing the following, however if you have multiple search criteria we could put those into an array, if you let me know what the search criteria is I can try and put something together for you. $Settings = _ReadLogFile('Settings=True') Edited February 1, 2017 by Subz Link to comment Share on other sites More sharing options...
aa2zz6 Posted February 1, 2017 Author Share Posted February 1, 2017 I think it'll probably be the same true/false and reflect the process name that's being preformed. 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