Что нового

Перевод макроса VBA CorelDraw на autoit. Не работает ExportEx в TIF.

306dr

Новичок
Сообщения
5
Репутация
0
Для интереса и для расширения возможностей макросов VBA для CorelDraw решил перевести их на AutoIt.
Уперся в проблему с экспортом через ExportEx.
Вылет с ошибкой:
(34) : ==> The requested action with this object has failed.:
$expflt = $myDoc.ExportEx($s, 772, 2, $expopt)
$expflt = $myDoc.ExportEx($s, 772, 2, $expopt)^ ERROR
>Exit code: 1 Time: 0.423
Помогите кто может, пожалуйста!

Код:
Global $myCorel= ObjCreate("CorelDRAW.Application")
Global $myDoc=$myCorel.ActiveDocument
Global $expopt = $myCorel.CreateStructExportOptions ;As StructExportOptions
Global $expflt ;As ExportFilter
Global $s

$myDoc.Unit = 3   
If $myCorel.Documents.Count = 0 Then
   MsgBox("","Нет открытых документов")
   Exit
EndIf

For $i = 1 To 100
   $s = "g:\Temp\" & $myDoc.Name & "_" & $i & ".tif"
   If NOT FileExists($s) Then
	  ExitLoop
   EndIf
Next
	 
With $expopt
   .UseColorProfile = True
   .ResolutionX = 150
   .ResolutionY = 150
   .ImageType = 5 ;cdrCMYKColorImage
   .AntiAliasingType = 1 ; 0-cdrNoAntiAliasing, 1-cdrNormalAntiAliasing, 2-cdrSupersampling
   .UseColorProfile = True
   .Compression = 1 ;cdrCompressionLZW
   .Dithered = False
   .Transparent = False
   .MaintainLayers = False
   .AlwaysOverprintBlack = True
EndWith
   
$expflt = $myDoc.ExportEx($s, 772, 2, $expopt) ;  ,Const cdrTIFF = 772 (&H304) ,cdrSelection=2, 

$expflt.Finish
 

sngr

AutoIT Гуру
Сообщения
1,010
Репутация
408
Код:
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Func MyErrFunc()
	MsgBox(4096, "AutoItCOM Test", "We intercepted a COM Error !" & @CRLF & @CRLF & _
			"err.description is: " & @TAB & $oMyError.description & @CRLF & _
			"err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
			"err.number is: " & @TAB & hex($oMyError.number, 8) & @CRLF & _
			"err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
			"err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
			"err.source is: " & @TAB & $oMyError.source & @CRLF & _
			"err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
			"err.helpcontext is: " & @TAB & $oMyError.helpcontext)
	Exit 1
EndFunc   ;==>MyErrFunc
Добавь это сверху - ошибка станет более информативной.
 
Автор
3

306dr

Новичок
Сообщения
5
Репутация
0
Спасибо за отклик! Вот:
We intercepted a COM Error !
err.description is:
err.windescription: Несовпадение
err.number is: 80020005
err.lastdllerror is: 0
err.scriptline is: 48
err.source is:
err.helpfile is:
err.helpcontext is: 0


Добавлено:
Сообщение автоматически объединено:

Те же объекты в VBA
Dim expopt As StructExportOptions
Set expopt = CreateStructExportOptions
Dim expflt As ExportFilter
Set expflt = ActiveDocument.ExportEx(s, cdrTIFF, cdrSelection, expopt)
 

sngr

AutoIT Гуру
Сообщения
1,010
Репутация
408
Приведи vba скрипт. Похоже ты где-то накосячил с типами данных.
 
Автор
3

306dr

Новичок
Сообщения
5
Репутация
0
Код:
Option Explicit
Sub TIF_1()
    If ActiveDocument Is Nothing Then Beep: Exit Sub
    Dim expopt As StructExportOptions
    Set expopt = CreateStructExportOptions
    Dim expflt As ExportFilter
    Dim d As Document
    Set d = ActiveDocument
    Dim s$
    Dim i As Long
    Dim j As Long
    For i = 1 To 100
        s = "g:\@Drx\Work\@out\" & Replace(d.Name, ".cdr", "") & "_" & Format(i, "00") & ".tif"
        If Dir(s) = "" Then
            Exit For
        End If
    Next i
      
    With expopt
        .UseColorProfile = True
        .ResolutionX = 150
        .ResolutionY = 150
        .ImageType = cdrCMYKColorImage
        .AntiAliasingType = cdrNormalAntiAliasing
        .UseColorProfile = True
        .Compression = cdrCompressionLZW
        .Dithered = False
        .Transparent = False
        .MaintainLayers = False
        .AlwaysOverprintBlack = True
    End With
    Set expflt = ActiveDocument.ExportEx(s, cdrTIFF, cdrSelection, expopt)
    expflt.Finish
    'ReForm.ReLabel.Caption = s
    'ReForm.Show
End Sub
 

sngr

AutoIT Гуру
Сообщения
1,010
Репутация
408
Попробуй перевести vba в vbs - гугель выдаёт много примеров таких переводов. С vbs в autoit переводить давольно легко; объяви все константы в начале скрипта и подставляй их, а не значения.
 
Автор
3

306dr

Новичок
Сообщения
5
Репутация
0
Попробуй перевести vba в vbs
Спасибо, попробую.


Добавлено:
Сообщение автоматически объединено:

Перевел, насколько хватило мозга, в VBS. Максимально упростил. Результат тот же
Строка: 10
Символ: 2
Ошибка: Несоответствие типа: 'ActiveDocurnent.ExportEx'
Код: 800A000D
Источник: Ошибка выполнения Microsoft VBScript
Код:
Option Explicit
Const cdrTIFF = &H304 '772 
Const cdrSelection = 1
Dim myCorel
Set myCorel= WScript.CreateObject("CorelDRAW.Application")
Dim expopt
With myCorel
	Set expopt = .CreateStructExportOptions
	With expopt
		.UseColorProfile = True
	End With
	.ActiveDocument.ExportEx "g:\Temp\temp.tif", cdrTIFF, cdrSelection, expopt
End With
Set myCorel = Nothing
WScript.Quit 0
Причем сделал другой пример в VBS - создание нового документа, где задается подобная структура. Все работает.
Код:
Option Explicit
Dim myCorel
Set myCorel= WScript.CreateObject("CorelDRAW.Application")
Dim createopt
With myCorel
	Set createopt =  .CreateStructCreateOptions
	With createopt
		.Name = "ZZZ"
	End With
	.CreateDocumentEx createopt
End With
Set myCorel = Nothing
WScript.Quit 0
 
Автор
3

306dr

Новичок
Сообщения
5
Репутация
0
Большое спасибо!
Действительно не хватало структуры палитры, хотя она для тифа не нужна и VBA ее по умолчанию не требует.
Привожу рабочий скрипт, вдруг кому понадобится инфа
Код:
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Func MyErrFunc()
    MsgBox(4096, "AutoItCOM Test", "We intercepted a COM Error !" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & hex($oMyError.number, 8) & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oMyError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oMyError.helpcontext)
    Exit 1
EndFunc   ;==>MyErrFunc

Global $myCorel= ObjCreate("CorelDRAW.Application")
Global $myDoc=$myCorel.ActiveDocument
Global $expopt = $myCorel.CreateStructExportOptions ;As StructExportOptions
Global $expflt ;As ExportFilter
Global $palopt = $myCorel.CreateStructPaletteOptions
;$exp = $cdr->ActiveDocument->ExportEx('J:\\1.jpg', cdrJPEG, cdrCurrentPage, $se, $palopt);
Global $s

Const $cdrCMYKColorImage = 5
Const $cdrNormalAntiAliasing = 1 ; 0-cdrNoAntiAliasing, 1-cdrNormalAntiAliasing, 2-cdrSupersampling
Const $cdrCompressionLZW = 1
Const $cdrTIFF = 0x304 ;Const cdrTIFF = 772 (&H304)
Const $cdrSelection = 2

$myDoc.Unit = 3   
If $myCorel.Documents.Count = 0 Then
   MsgBox("","Нет открытых документов")
   Exit
EndIf

For $i = 1 To 100
   $s = "g:\@Drx\Work\@out\" & $myDoc.Name & "_" & $i & ".tif"
   If NOT FileExists($s) Then
	  ExitLoop
   EndIf
Next
	 
With $expopt
   .UseColorProfile = True
   .ResolutionX = 150
   .ResolutionY = 150
   .ImageType = $cdrCMYKColorImage
   .AntiAliasingType = $cdrNormalAntiAliasing
   .UseColorProfile = True
   .Compression = $cdrCompressionLZW
   .Dithered = False
   .Transparent = False
   .MaintainLayers = False
   .AlwaysOverprintBlack = True
EndWith
   
$expflt = $myDoc.ExportEx($s, $cdrTIFF, $cdrSelection, $expopt, $palopt) 

$expflt.Finish
 
Верх