Jump to content

Recommended Posts

Posted

Hi everybody,

I have script that already work on windows xp + corel X5 , but not work on windows 7 + corel x7. 

Here is a piece of code : 

#include <C:\Program Files\AutoIt3\Include\Word.au3>
$type = "OŚ"
If $CmdLine[0] == 0 Then
    $WindowName = "CorelDRAW X7 - [" & @ScriptDir & "\corelfile.cdr]"
    If WinExists($WindowName) Then
        If FileExists(@ScriptDir & "\2.pdf") Then
            If FileDelete(@ScriptDir & "\2.pdf") == 0 Then Exit MsgBox(16, Default, "connot delete 2.pdf w " & @ScriptDir)
        EndIf
        $oCorel = ObjCreate("CorelDRAW.Application")
        $oDoc = $oCorel.ActiveDocument
        With $oDoc.PDFSettings
            .PublishRange = 0
            .BitmapCompression = 4      ;CdrPDFVBA.pdfJP2
            .JPEGQualityFactor = 40
            .TextAsCurves = False
            .EmbedFonts = False
            .EmbedBaseFonts = False
            .TrueTypeToType1 = True
            .SubsetFonts = True
            .SubsetPct = 80
            .CompressText = True
            .Encoding = 1               ;CdrPDFVBA.pdfBinary
            .DownsampleColor = True
            .DownsampleGray = True
            .DownsampleMono = True
            .ColorResolution = 200
            .MonoResolution = 250
            .GrayResolution = 250
            .Hyperlinks = False
            .Bookmarks = False
            .Thumbnails = False
            .Startup = 0
            .ComplexFillsAsBitmaps = True
            .Overprints = False
            .Halftones = False
            .SpotColors = True
            .MaintainOPILinks = False
            .FountainSteps = 256
            .EPSAs = 1                  ;CdrPDFVBA.pdfPreview
            .pdfVersion = 7
            .IncludeBleed = False
            .Bleed = 31750
            .Linearize = True
            .CropMarks = False
            .RegistrationMarks = False
            .DensitometerScales = False
            .FileInformation = False
            .ColorMode = 0              ;CdrPDFVBA.pdfRGB
            ;.UseColorProfile = 1
            .ColorProfile = 0           ;CdrPDFVBA.pdfSeparationProfile 0 - composite 1 -separation
            .EmbedFile = False
            .JP2QualityFactor = 50
            .TextExportMode = 0         ;CdrPDFVBA.pdfTextAsUnicode
            .PrintPermissions = 0       ;CdrPDFVBA.pdfPrintPermissionNone
            .EditPermissions = 0        ;CdrPDFVBA.pdfEditPermissionNone
            .ContentCopyingAllowed = False
            .OpenPassword = ""
            .PermissionPassword = ""
            .ConvertSpotColors = True
            .EncryptType = 1            ;CdrPDFVBA.pdfEncryptTypeStandard
            .OutputSpotColorsAs = 0     ;CdrPDFVBA.pdfSpotAsSpot
        EndWith
        $oDoc.PublishToPDF(@ScriptDir & "\2.pdf")
        Exit MsgBox(64, Default, "Done", 1)
    EndIf
EndIf

..

 

Posted

#include <C:\Program Files\AutoIt3\Include\Word.au3>
$type = "OŚ"
If $CmdLine[0] == 0 Then
    $WindowName = "CorelDRAW X7 - [" & @ScriptDir & "\corelfile.cdr]"
    If WinExists($WindowName) Then
        If FileExists(@ScriptDir & "\2.pdf") Then
            If FileDelete(@ScriptDir & "\2.pdf") == 0 Then Exit MsgBox(16, Default, "connot delete 2.pdf w " & @ScriptDir)
        EndIf
        $oCorel = ObjCreate("CorelDRAW.Application")
        $oDoc = $oCorel.ActiveDocument
        With $oDoc.PDFSettings
            .PublishRange = 0
            .BitmapCompression = 4      ;CdrPDFVBA.pdfJP2
            .JPEGQualityFactor = 40
            .TextAsCurves = False
            .EmbedFonts = False
            .EmbedBaseFonts = False
            .TrueTypeToType1 = True
            .SubsetFonts = True
            .SubsetPct = 80
            .CompressText = True
            .Encoding = 1               ;CdrPDFVBA.pdfBinary
            .DownsampleColor = True
            .DownsampleGray = True
            .DownsampleMono = True
            .ColorResolution = 200
            .MonoResolution = 250
            .GrayResolution = 250
            .Hyperlinks = False
            .Bookmarks = False
            .Thumbnails = False
            .Startup = 0
            .ComplexFillsAsBitmaps = True
            .Overprints = False
            .Halftones = False
            .SpotColors = True
            .MaintainOPILinks = False
            .FountainSteps = 256
            .EPSAs = 1                  ;CdrPDFVBA.pdfPreview
            .pdfVersion = 7
            .IncludeBleed = False
            .Bleed = 31750
            .Linearize = True
            .CropMarks = False
            .RegistrationMarks = False
            .DensitometerScales = False
            .FileInformation = False
            .ColorMode = 0              ;CdrPDFVBA.pdfRGB
            ;.UseColorProfile = 1
            .ColorProfile = 0           ;CdrPDFVBA.pdfSeparationProfile 0 - composite 1 -separation
            .EmbedFile = False
            .JP2QualityFactor = 50
            .TextExportMode = 0         ;CdrPDFVBA.pdfTextAsUnicode
            .PrintPermissions = 0       ;CdrPDFVBA.pdfPrintPermissionNone
            .EditPermissions = 0        ;CdrPDFVBA.pdfEditPermissionNone
            .ContentCopyingAllowed = False
            .OpenPassword = ""
            .PermissionPassword = ""
            .ConvertSpotColors = True
            .EncryptType = 1            ;CdrPDFVBA.pdfEncryptTypeStandard
            .OutputSpotColorsAs = 0     ;CdrPDFVBA.pdfSpotAsSpot
        EndWith
        $oDoc.PublishToPDF(@ScriptDir & "\2.pdf")
        Exit MsgBox(64, Default, "Done", 1)
    EndIf
EndIf

If FileExists(@ScriptDir & "\1.pdf") Then
    If FileDelete(@ScriptDir & "\1.pdf") == 0 Then Exit MsgBox(16, Default, "connot delete 1.pdf w " & @ScriptDir)
EndIf
If FileExists(@ScriptDir & "\document.doc") == 0 Then Exit MsgBox(16, Default, "No file " & @ScriptDir & "\document.doc")
If FileExists(@ScriptDir & "\2.pdf") == 0 Then Exit MsgBox(16, Default, "No file " & @ScriptDir & "\2.pdf")
$oWordApp = _WordCreate(@ScriptDir & "\document.doc", 0, 0, 0)
$oDoc = _WordDocGetCollection($oWordApp, 0)
$oDoc.Range.Font.Color = 0
For $i=1 To $oDoc.Sections.Count()
    $oDoc.Sections($i).Headers(1).Range.Font.Color = 0
    $oDoc.Sections($i).Footers(1).Range.Font.Color = 0
Next
$path = @ScriptDir

If StringRight(@ScriptDir, StringLen($type)+1) == "\" & $type Then $path = StringTrimRight(@ScriptDir, StringLen($type)+1)

$SiteName = StringTrimLeft($path, StringInStr($path, "\", 0, -1))

If $CmdLine[0] == 1 AND $CmdLine[1] == "DRUK" Then
    If $oDoc.Shapes.Count() <> 2 Then
        _WordDocClose($oDoc, 0)
        _WordQuit($oWordApp)
        Exit MsgBox(16, Default, "not enaught " & $PathDoc)
    EndIf
    $oDoc.Shapes(2).Delete
    $range = $oDoc.Content
    $range.Find.Execute("Egzemplarz nr    1 / 1", False, False, True)
    If $range.Find.Found = False Then _WordDocFindReplace($oDoc, "Egzemplarz nr    1 / ", "Egzemplarz nr      / ")
    $oDoc.ExportAsFixedFormat(@ScriptDir & "\1.pdf", 17, False, 0, 0)
    _WordDocClose($oDoc, 0)
    _WordQuit($oWordApp)
    If FileExists(@ScriptDir & "\" & $SiteName & " " & $type & " DRUK.pdf") Then
        If FileDelete(@ScriptDir & "\" & $SiteName & " " & $type & " DRUK.pdf") == 0 Then Exit MsgBox(16, Default, "connot delete " & $SiteName & " " & $type & " DRUK.pdf")
    EndIf
    For $time=1 To 140
        If FileExists(@ScriptDir & "\1.pdf") == 1 Then
            If FileExists(@ScriptDir & "\2.pdf") == 1 Then
                $line = 'java  -Dlog4j.configuration=console-log4j.xml -jar "C:\Program Files\pdfsam\lib\pdfsam-console-2.3.1e.jar" -compressed -f "' & _
                        @ScriptDir & '\1.pdf" -f "' & @ScriptDir & '\2.pdf" -o "' & @ScriptDir & '\' & $SiteName & ' ' & $type & ' DRUK.pdf" -overwrite concat'
                If RunWait($line, "", @SW_HIDE) == 1 Then Exit MsgBox(16, Default, "error while compare " & @ScriptDir)
                Exit MsgBox(64, Default, "Done", 1)
            EndIf
        EndIf
        Sleep(50)
    Next
    Exit MsgBox(16, Default, "Error pdf creating. t > 7s")
Else
    $oDoc.ExportAsFixedFormat(@ScriptDir & "\1.pdf", 17, False, 0, 0)
    _WordDocClose($oDoc, 0)
    _WordQuit($oWordApp)
    If FileExists(@ScriptDir & "\" & $SiteName & " " & $type & ".pdf") Then
        If FileDelete(@ScriptDir & "\" & $SiteName & " " & $type & ".pdf") == 0 Then Exit MsgBox(16, Default, "connot delete " & $SiteName & " " & $type & ".pdf")
    EndIf
    For $time=1 To 140
        If FileExists(@ScriptDir & "\1.pdf") == 1 Then
            If FileExists(@ScriptDir & "\2.pdf") == 1 Then
                $line = 'java  -Dlog4j.configuration=console-log4j.xml -jar "C:\Program Files\pdfsam\lib\pdfsam-console-2.3.1e.jar" -compressed -f "' & _
                    @ScriptDir & '\1.pdf" -f "' & @ScriptDir & '\2.pdf" -o "' & @ScriptDir & '\' & $SiteName & ' ' & $type & '.pdf" -overwrite concat'
                Run($line, "", @SW_HIDE)
                Exit MsgBox(64, Default, "Done", 1)
            EndIf
        EndIf
        Sleep(50)
    Next
    Exit MsgBox(16, Default, "Error pdf creating. t > 7s")
EndIf
 

Posted (edited)

This script couldn't throw the error, as it is exiting before this line (72) can be executed line 64: Exit MsgBox(64, Default, "Done", 1).

  • Are you sure the title for WinExits is correct?
  • Are you also sure Corel is active?
Edited by AutoBert
Posted

@AutoBert - I would go one step further and check if the block of code in the outermost IF statement is being executed.  He said the script exit message is consistent with line 72.  That makes me think the outermost IF is skipped, that entire block is skipped and there are no objects, and therefore no PDF created (which causes exit on 72).  Also, why is this condition necessary to test for no command line parameters (I am assuming that is what this is doing)?  

If $CmdLine[0] == 0 Then

You could eliminate that condition.  Alternatively, one quick way to test to see if the outermost IF is working could be to add this on the line following the if statement:

msgbox(0,"Hello","I am talking to you from the IF statement")

Then you could add a similar message after this to test your theory:

If WinExists($WindowName) Then
msgbox(0,"Hello again","The window exists")

 

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Posted (edited)
22 hours ago, Dhomson said:

I have script that already work on windows xp + corel X5 ,

This script never runs as already mentioned it exit in line 64, try this one:

#include <C:\Program Files\AutoIt3\Include\Word.au3>
$type = "OS"
$iErr=1
If $CmdLine[0] == 0 Then
    $iErr=0
    $WindowName = "CorelDRAW X7 - [" & @ScriptDir & "\corelfile.cdr]"
    If WinExists($WindowName) Then
        If FileExists(@ScriptDir & "\2.pdf") Then
            If FileDelete(@ScriptDir & "\2.pdf") == 0 Then Exit MsgBox(16, Default, "connot delete 2.pdf w " & @ScriptDir)
        $oCorel = ObjCreate("CorelDRAW.Application")
        $oDoc = $oCorel.ActiveDocument
        With $oDoc.PDFSettings
            .PublishRange = 0
            .BitmapCompression = 4      ;CdrPDFVBA.pdfJP2
            .JPEGQualityFactor = 40
            .TextAsCurves = False
            .EmbedFonts = False
            .EmbedBaseFonts = False
            .TrueTypeToType1 = True
            .SubsetFonts = True
            .SubsetPct = 80
            .CompressText = True
            .Encoding = 1               ;CdrPDFVBA.pdfBinary
            .DownsampleColor = True
            .DownsampleGray = True
            .DownsampleMono = True
            .ColorResolution = 200
            .MonoResolution = 250
            .GrayResolution = 250
            .Hyperlinks = False
            .Bookmarks = False
            .Thumbnails = False
            .Startup = 0
            .ComplexFillsAsBitmaps = True
            .Overprints = False
            .Halftones = False
            .SpotColors = True
            .MaintainOPILinks = False
            .FountainSteps = 256
            .EPSAs = 1                  ;CdrPDFVBA.pdfPreview
            .pdfVersion = 7
            .IncludeBleed = False
            .Bleed = 31750
            .Linearize = True
            .CropMarks = False
            .RegistrationMarks = False
            .DensitometerScales = False
            .FileInformation = False
            .ColorMode = 0              ;CdrPDFVBA.pdfRGB
            ;.UseColorProfile = 1
            .ColorProfile = 0           ;CdrPDFVBA.pdfSeparationProfile 0 - composite 1 -separation
            .EmbedFile = False
            .JP2QualityFactor = 50
            .TextExportMode = 0         ;CdrPDFVBA.pdfTextAsUnicode
            .PrintPermissions = 0       ;CdrPDFVBA.pdfPrintPermissionNone
            .EditPermissions = 0        ;CdrPDFVBA.pdfEditPermissionNone
            .ContentCopyingAllowed = False
            .OpenPassword = ""
            .PermissionPassword = ""
            .ConvertSpotColors = True
            .EncryptType = 1            ;CdrPDFVBA.pdfEncryptTypeStandard
            .OutputSpotColorsAs = 0     ;CdrPDFVBA.pdfSpotAsSpot
        EndWith
        $oDoc.PublishToPDF(@ScriptDir & "\2.pdf")
        ;Exit MsgBox(64, Default, "Done", 1)
        MsgBox(64, Default, "Done", 1)
    Else
        $iErr=2
    EndIf
    If $iErr Then MsgBox(64, "Error", $iErr, 10)
EndIf
If $iErr=0 Then ConsoleWrite('corel seems to work'&@CRLF)

If FileExists(@ScriptDir & "\1.pdf") Then
    If FileDelete(@ScriptDir & "\1.pdf") == 0 Then Exit MsgBox(16, Default, "connot delete 1.pdf w " & @ScriptDir)
EndIf
If FileExists(@ScriptDir & "\document.doc") == 0 Then Exit MsgBox(16, Default, "No file " & @ScriptDir & "\document.doc")
If FileExists(@ScriptDir & "\2.pdf") == 0 Then Exit MsgBox(16, Default, "No file " & @ScriptDir & "\2.pdf")
ConsoleWrite('creating word document'&@CRLF)
$oWordApp = _WordCreate(@ScriptDir & "\document.doc", 0, 0, 0)
$oDoc = _WordDocGetCollection($oWordApp, 0)
$oDoc.Range.Font.Color = 0
For $i=1 To $oDoc.Sections.Count()
    $oDoc.Sections($i).Headers(1).Range.Font.Color = 0
    $oDoc.Sections($i).Footers(1).Range.Font.Color = 0
Next
$path = @ScriptDir

If StringRight(@ScriptDir, StringLen($type)+1) == "\" & $type Then $path = StringTrimRight(@ScriptDir, StringLen($type)+1)

$SiteName = StringTrimLeft($path, StringInStr($path, "\", 0, -1))

If $CmdLine[0] == 1 AND $CmdLine[1] == "DRUK" Then
    If $oDoc.Shapes.Count() <> 2 Then
        _WordDocClose($oDoc, 0)
        _WordQuit($oWordApp)
        Exit MsgBox(16, Default, "not enaught " & $PathDoc)
    EndIf
    $oDoc.Shapes(2).Delete
    $range = $oDoc.Content
    $range.Find.Execute("Egzemplarz nr    1 / 1", False, False, True)
    If $range.Find.Found = False Then _WordDocFindReplace($oDoc, "Egzemplarz nr    1 / ", "Egzemplarz nr      / ")
    $oDoc.ExportAsFixedFormat(@ScriptDir & "\1.pdf", 17, False, 0, 0)
    _WordDocClose($oDoc, 0)
    _WordQuit($oWordApp)
    If FileExists(@ScriptDir & "\" & $SiteName & " " & $type & " DRUK.pdf") Then
        If FileDelete(@ScriptDir & "\" & $SiteName & " " & $type & " DRUK.pdf") == 0 Then Exit MsgBox(16, Default, "connot delete " & $SiteName & " " & $type & " DRUK.pdf")
    EndIf
    For $time=1 To 140
        If FileExists(@ScriptDir & "\1.pdf") == 1 Then
            If FileExists(@ScriptDir & "\2.pdf") == 1 Then
                $line = 'java  -Dlog4j.configuration=console-log4j.xml -jar "C:\Program Files\pdfsam\lib\pdfsam-console-2.3.1e.jar" -compressed -f "' & _
                        @ScriptDir & '\1.pdf" -f "' & @ScriptDir & '\2.pdf" -o "' & @ScriptDir & '\' & $SiteName & ' ' & $type & ' DRUK.pdf" -overwrite concat'
                If RunWait($line, "", @SW_HIDE) == 1 Then Exit MsgBox(16, Default, "error while compare " & @ScriptDir)
                Exit MsgBox(64, Default, "Done", 1)
            EndIf
        EndIf
        Sleep(50)
    Next
    Exit MsgBox(16, Default, "Error pdf creating. t > 7s")
Else
    $oDoc.ExportAsFixedFormat(@ScriptDir & "\1.pdf", 17, False, 0, 0)
    _WordDocClose($oDoc, 0)
    _WordQuit($oWordApp)
    If FileExists(@ScriptDir & "\" & $SiteName & " " & $type & ".pdf") Then
        If FileDelete(@ScriptDir & "\" & $SiteName & " " & $type & ".pdf") == 0 Then Exit MsgBox(16, Default, "connot delete " & $SiteName & " " & $type & ".pdf")
    EndIf
    For $time=1 To 140
        If FileExists(@ScriptDir & "\1.pdf") == 1 Then
            If FileExists(@ScriptDir & "\2.pdf") == 1 Then
                $line = 'java  -Dlog4j.configuration=console-log4j.xml -jar "C:\Program Files\pdfsam\lib\pdfsam-console-2.3.1e.jar" -compressed -f "' & _
                    @ScriptDir & '\1.pdf" -f "' & @ScriptDir & '\2.pdf" -o "' & @ScriptDir & '\' & $SiteName & ' ' & $type & '.pdf" -overwrite concat'
                Run($line, "", @SW_HIDE)
                Exit MsgBox(64, Default, "Done", 1)
            EndIf
        EndIf
        Sleep(50)
    Next
    Exit MsgBox(16, Default, "Error pdf creating. t > 7s")
EndIf

Post output of sciteconsole after tested.

Edited by AutoBert

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
×
×
  • Create New...