OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   CorelDRAW curves to Adobe Photoshop paths converter (http://forum.oberonplace.com/showthread.php?t=327)

d-signer 05-01-2004 02:49

CorelDRAW curves to Adobe Photoshop paths converter
Disclaimer: English is not my native language.

Known that Adobe Photoshop can obtain vector data (paths) only via clipboard. First vector shape must be copied into clipboard in the Adobe Illustrator or may be dragging from them to Photoshop document.

With CorelDRAW this is not works. - Even vector object being copied into clipboard will be pasted into the Photoshop document you'll get it as raster image at 72 dpi resolution w/o transparency.

I thought that this can be made by converting data in the clipboard between Corel and Adobe specifics. But I was not found any info about format of this data. Reengineering it seems to be hard too.

So, recently I stumbled on the Photoshop File Format.pdf (from Adobe Photoshop 6 SDK) where described Path Resource Format of the Adobe Photoshop Document.

I guess that is possible to save CorelDraw vector data into PSD file using VBA based on the VBA documentation and Photoshop SDK.

Now for obtaining vector object in the Photoshop I must use Illustrator for opening exported by CorelDRAW EPS file.

But it would like directly.

This could become commercial product.

What your opinion?

Alex 08-01-2004 15:14

Re: CorelDRAW curves to Adobe Photoshop paths converter
I believe that when you copy a path from Illustrator, it is placed on the clipboard in AI format and Photoshop can recognize the format and paste it back into its own document as a clipping path.

Now I think that this can be emulated from CorelDRAW side. Since CorelDRAW has AI export, maybe when you export the object to a temporary file, then place the contents of the file on the clipboard with the proper format ID, then probably Photoshop will understand it.

I might play with this to see if my guess is far from reality or if it is actually feasible.

Alex 08-01-2004 16:08

Re: CorelDRAW curves to Adobe Photoshop paths converter

Try this code. It was written under CorelDRAW 11 and should work with Illustrator and Photoshop. But because I don't have either handy at the time, I can only hope. I will test it later (tomorrow?) to be sure but you can play with it as well.


Attribute VB_Name = "CopyAI"
Option Explicit

Private Declare Function RegisterClipboardFormat Lib "user32" Alias "RegisterClipboardFormatA" (ByVal lpString As String) As Long
Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long

Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long

Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _
                                ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, _
                                ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, ByVal lpBuffer As Long, ByVal nNumberOfBytesToRead As Long, _
                                lpNumberOfBytesRead As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long

Sub CopySelectionAsAI()
    Dim hFile As Long
    Dim nFileSize As Long
    Dim expflt As ExportFilter
    Dim sTempFile As String
    Dim hMem As Long
    Dim lpMemPtr As Long
    Dim nBytesRead As Long
    Dim nClipFmt As Long
    nClipFmt = RegisterClipboardFormat("ADOBE AI3")
    sTempFile = "C:\Temp.ai"
    Set expflt = ActiveDocument.ExportEx(sTempFile, cdrAI, cdrSelection)
    With expflt
        .Version = 0 ' FilterAILib.aiVersion7
        .TextAsCurves = False
        .Platform = 0 ' FilterAILib.aiPC
        .ConvertSpotColors = False
        .UseColorProfile = False
        .SimulateOutlines = False
        .SimulateFills = True
        .IncludePlacedImages = True
        .IncludePreview = False
    End With
    Set expflt = Nothing
    hFile = CreateFile(sTempFile, &H80000000, 0, 0, 3, &H80, 0)
    If hFile <> -1 Then
        nFileSize = GetFileSize(hFile, 0)
        hMem = GlobalAlloc(2, nFileSize)
        If hMem <> 0 Then
            lpMemPtr = GlobalLock(hMem)
            If lpMemPtr Then
                If ReadFile(hFile, lpMemPtr, nFileSize, nBytesRead, 0) <> 0 And nBytesRead = nFileSize Then
                    GlobalUnlock hMem
                    OpenClipboard AppWindow.Handle
                    SetClipboardData nClipFmt, hMem
                    GlobalUnlock hMem
                    GlobalFree hMem
                End If
                GlobalFree hMem
            End If
        End If
        CloseHandle hFile
    End If
    DeleteFile sTempFile
End Sub

So, essentially, this code exports the current selection to AI7 file format, then read the contents of the file into memory and sets it to the clipboards as "ADOBE AI3" data format which what AI8 seems to put when you copy objects to clipboards.

The code above uses some Windows APIs to allocate memory and read the file in which could technically be rewritten using VBA methods (dynamic array and GET statement) but I decided to do it this way as I will have to put a memory handle on the clipboard anyway.

To use the macro:

1. Create an empty module in any VBA project (e.g. in "GlobalMacros").
2. Paste the code above
3. Create an object (or objects) in CorelDRAW 11
4. Run CopySelectionAsAI macro.
5. Go to Illustrator (or Photoshop) and paste.

This should work if I have done everything correctly.

Let me know how it goes and good luck :)

Alex 09-01-2004 09:10

Copy to Illustrator/Photoshop
Hey, it works. :super: I just verified the above script and it works perfectly. It allows you to copy CorelDRAW objects in Illustrator formats so that Illustrator or Photoshop can paste them natively.

I verified the thing with Illustrator 10 and Photoshop 7 and it worked.

I will probably create a paste routine as well so you can copy from Illy/photoshop and paste it directly to CorelDRAW and package it as a macro and make it available for a download.

Will let you know how it goes.

d-signer 13-01-2004 06:48

2 Attachment(s)
Wow, great! It's works really! :D A lot of thanks!!!

But, while I was waiting your answer I wrote a script which use Corel PhotoPanit feature - saving as Photoshop (PSD) file with paths (but unclosed paths).

And I found one very important thing - PP makes our paths with snapping path edges to image pixels!!!

In the attachment it's shown.

Dark green rounded rectangle - pasted shape layer from clipboard.
Light green rounded rectangle - exported shape layer via PhotoPaint

As you see the dark green shape has straight edges WITH half-transparent pixels that produces blurry edges, and light green shapes WITHOUT ones. Both shapes taken from one CorelDRAW object.

Code of my script here:

Sub CurvesToPsd()
Dim d As CorelDRAW.Document
Dim sh As CorelDRAW.Shape
Dim shNum() As String
Dim shAdd As String, shOmit As String
Dim i As Integer, s As String
Dim pPaint As Object

If CorelDRAW.Documents.Count = 0 Then Exit Sub
Set d = CorelDRAW.ActiveDocument
i = CorelDRAW.ActiveSelection.Shapes.Count
If i = 0 Then Exit Sub
If i > 32 Then MsgBox "Too many objects are selected. Script aborted", vbCritical, "Get Shapes": Exit Sub
If d.FullFileName = "" Then MsgBox "You must save the document before executing this script.", vbInformation, "Get Shapes": Exit Sub
d.Unit = cdrMillimeter

For Each sh In CorelDRAW.ActiveSelection.Shapes
    If sh.Type = cdrCurveShape Or _
      sh.Type = cdrEllipseShape Or _
      sh.Type = cdrRectangleShape Or _
      sh.Type = cdrPolygonShape Then
      shAdd = shAdd & CStr(sh.ObjectData("CDRStaticID").Value) & vbNullChar
      shOmit = shOmit & CStr(sh.ObjectData("CDRStaticID").Value) & vbNullChar
    End If
Next sh
shNum = Split(shAdd, vbNullChar)

Set pPaint = CreateObject("CorelPhotoPaint.Application")
pPaint.Visible = False

pPaint.CorelScript.FileNew (d.ActivePage.SizeWidth / 25.4) * 300, _
                          (d.ActivePage.SizeHeight / 25.4) * 300, _
                          5, 300, 300, False, False, 1, 0, 0, 0, 0, 0, 0, 0, 0, False
For i = LBound(shNum) To UBound(shNum) - 1
    Set sh = CorelDRAW.ActivePage.Shapes.FindShape(, , CLng(Val(shNum(i))))
    s = d.FilePath & "shape" & Format(shNum(i), "000") & ".cmx"
    d.ExportEx(s, cdrCMX6, cdrSelection).Finish
    pPaint.CorelScript.PathImportVector s, 1, 1
Next i

pPaint.CorelScript.FileSave d.FilePath & "shapes.psd", 788, 0
shAdd = shAdd & shOmit
shNum = Split(shAdd, vbNullChar)

For i = LBound(shNum) To UBound(shNum) - 1
    Set sh = CorelDRAW.ActivePage.Shapes.FindShape(, , CLng(Val(shNum(i))))
Next i

End Sub

With this script I can get all needed shapes in one psd-file.

Some problem was here - only CorelScript object is accessible in PP from CorelDRAW script. But it works.

I do not remove temporary files becouse I have one app which it makes automatically after the project will be finished.

I also found that PP's paths cannot be copyed into clipboard and cannot be pasted into PP document.

(Have you heard about JAW in that forum? - http://forum.rudtp.ru/showthread.php?t=20062)

d-signer 13-01-2004 09:08

I change export to ai options:


With expflt
        .Version = 0 ' FilterAILib.aiVersion7
        .TextAsCurves = True
        .Platform = 0 ' FilterAILib.aiPC
        .ConvertSpotColors = False
        .UseColorProfile = False
        .SimulateOutlines = False
        .SimulateFills = False
        .IncludePlacedImages = False
        .IncludePreview = False
 End With

With it works better.

Alex 13-01-2004 09:26

Are you sure IncludePlacedImages should be False? I think this will omit any bitmaps from CorelDRAW... But I may be wrong here.

Converting text to curves may not be the best option for everybody too.

I see though how setting SimulateFills to False could help.

But the good thing is that you can fine tune it to your taste/needs :)

d-signer 13-01-2004 09:47

Text as 'artistic text' could not be pasted as text.

It described in AI and PS documentation - All texts MUST be converted into paths before. Only after doing it you can copy (or control+Drag) paths from Ai to Photshop.

.SimulateOutlines = False - in work path no outline width
.SimulateFills = False - if 'True' then paths becomes sliced.
.IncludePlacedImages = False ' in path is not to be

Also, I think that it could be a good idea to get temporary folder via known API 'GetTemPath'

d-signer 15-01-2004 00:32

3 Attachment(s)
I recently try to get DRAW converted to curve text object via PHOTOPAINT and as I wrote above I'v got perfectly paths in the Photoshop!!!

See attachment. Compare.

Photopaint is great!

All times are GMT -5. The time now is 11:12.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com