jdelaney Posted November 8, 2012 Posted November 8, 2012 (edited) This is more suited for a microsoft forum, but was hoping someone had some workarounds, here. I'm taking screenshots which may or may not contain text. When no text is present, the .OCR fails, and script stops: $miDoc.Ocr($Lang, True, False) $miDoc.Ocr($Lang, True, False)^ ERROR Any ideas to stop the run from terminating? short reproducer: expandcollapse popup#include <ScreenCapture.au3> #include <Array.au3> $pid = Run ( @WindowsDir & "system32mspaint.exe" ) While Not WinExists ( "[CLASS:MSPaintApp]" ) WEnd $hWin = WinGetHandle ( "[CLASS:MSPaintApp]" ) WinActivate ( $hWin ) WinSetState ( $hWin, "", @SW_MAXIMIZE ) While Not BitAND(WinGetState ( $hWin ),32) WEnd $aWinPos = WinGetPos ( $hWin ) _ScreenCapture_Capture ( @DesktopDir & "temp1.gif", $aWinPos[0]+10, $aWinPos[1]+10, $aWinPos[0]+250, $aWinPos[1]+250 ) ; include text _ScreenCapture_Capture ( @DesktopDir & "temp2.gif", $aWinPos[0]+200, $aWinPos[1]+200, $aWinPos[0]+250, $aWinPos[1]+250 ) ; no text WinClose ( $hWin ) $aWords = Var_OCRGet ( @DesktopDir & "temp1.gif" ) _ArrayDisplay ( $aWords ) $aWords = Var_OCRGet ( @DesktopDir & "temp2.gif" ) _ArrayDisplay ( $aWords ) Func Var_OCRGet($Image, $Lang=9) ;$giSubFunctionCounter += 1 ;If $gbPerformLog Then Var_SetLogAndActOnState(2, 4, "Var_OCRGet()", "Func=[Var_OCRGet]: Start with Params=[" & $Image & "].", $gbDisplayInformMessage, $gbTerminateOnFailure) Local $sArray[1], $oWord Local $miDoc = ObjCreate("MODI.Document") $miDoc.Create($Image) If @error Then ;If $gbPerformLog Then Var_SetLogAndActOnState(0, 1, "Var_OCRGet()", "Func=[ObjCreate]: UNable to create object=[" & "MODI.Document" & "].", $gbDisplayInformMessage, $gbTerminateOnFailure) ;$giSubFunctionCounter -= 1 Return SetError(1) EndIf ;~ $miDoc.Images(0).OCR ;~ $test = $miDoc.Images(0).Layout ;~ ConsoleWrite ( $test.NumChars & @crlf ) $miDoc.Ocr($Lang, True, False) If @error Then ;If $gbPerformLog Then Var_SetLogAndActOnState(0, 1, "Var_OCRGet()", "Func=[.Ocr]: UNable run method=[" & ".Ocr" & "].", $gbDisplayInformMessage, $gbTerminateOnFailure) ;$giSubFunctionCounter -= 1 Return SetError(2) EndIf For $oWord In $miDoc.Images(0).Layout.Words ReDim $sArray[UBound($sArray)+1] $sArray[UBound($sArray)-1] = $oWord.Text Next $sArray[0] = UBound($sArray)-1 ;If $gbPerformLog Then Var_SetLogAndActOnState(2, 3, "Var_OCRGet()", "Func=[Var_OCRGet]: returning array of text=[UBound=(" & UBound ( $sArray ) & ")].", $gbDisplayInformMessage, $gbTerminateOnFailure) ;$giSubFunctionCounter -= 1 Return $sArray EndFunc Edited November 8, 2012 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
water Posted November 8, 2012 Posted November 8, 2012 When working with COM you need a COM error handler. Please have a look at ObjEvent on how to implement such a function. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
jdelaney Posted November 9, 2012 Author Posted November 9, 2012 (edited) Thanks, water.I was having difficulties, but that was because in my ocr function, I was re-instantiating the autoit.error ObjEvent without killing it prior to exit.I take that back...still having some issues with bad autoit exits:err.number is: -2147352567err.windescription:err.description is: OCR running errorerr.source is: err.helpfile is: err.helpcontext is: 0err.lastdllerror is: 0err.scriptline is: 4194err.retcode is: -959967087!>08:24:05 AutoIT3.exe ended.rc:-1073741811>Exit code: -1073741811 Time: 24.317edit...whoops, wasn't validating my object prior to method calls, all fixed Edited November 9, 2012 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
water Posted November 9, 2012 Posted November 9, 2012 -2147352567 is hex 0x80020009 - exception detected: This could be everything.A quick google search brought some hits on this subject. There are other people who seem to have the same problem.I searched for: miDoc.Ocr when there is "no text"So it seems to be more a MS than an AutoIt problem. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
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