Jump to content

MODI.Document fails when no text


 Share

Recommended Posts

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:

#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 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.
Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

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: -2147352567

err.windescription:

err.description is: OCR running error

err.source is:

err.helpfile is:

err.helpcontext is: 0

err.lastdllerror is: 0

err.scriptline is: 4194

err.retcode is: -959967087

!>08:24:05 AutoIT3.exe ended.rc:-1073741811

>Exit code: -1073741811 Time: 24.317

edit...whoops, wasn't validating my object prior to method calls, all fixed

Edited 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.
Link to comment
Share on other sites

-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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...