OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-01-2004, 03:49
d-signer
Guest
 
Posts: n/a
Default 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?
Reply With Quote
  #2  
Old 08-01-2004, 16:14
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default 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.
Reply With Quote
  #3  
Old 08-01-2004, 17:08
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: CorelDRAW curves to Adobe Photoshop paths converter

Ok,

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.

Code:
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
        .Finish
    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
                    EmptyClipboard
                    SetClipboardData nClipFmt, hMem
                    CloseClipboard
                Else
                    GlobalUnlock hMem
                    GlobalFree hMem
                End If
            Else
                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
Reply With Quote
  #4  
Old 09-01-2004, 10:10
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Copy to Illustrator/Photoshop

Hey, it works. 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.
Reply With Quote
  #5  
Old 13-01-2004, 07:48
d-signer
Guest
 
Posts: n/a
Default

Wow, great! It's works really! 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:
Code:
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
    Else
       shOmit = shOmit & CStr(sh.ObjectData("CDRStaticID").Value) & vbNullChar
    End If
Next sh
shNum = Split(shAdd, vbNullChar)
CorelDRAW.ActivePage.Shapes.All.RemoveFromSelection

Set pPaint = CreateObject("CorelPhotoPaint.Application")
DoEvents
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))))
    sh.AddToSelection
    s = d.FilePath & "shape" & Format(shNum(i), "000") & ".cmx"
    d.ExportEx(s, cdrCMX6, cdrSelection).Finish
    sh.RemoveFromSelection
    pPaint.CorelScript.PathImportVector s, 1, 1
Next i

pPaint.CorelScript.FileSave d.FilePath & "shapes.psd", 788, 0
pPaint.CorelScript.FileClose
pPaint.CorelScript.FileExit
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))))
    sh.AddToSelection
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)

Last edited by d-signer; 22-05-2006 at 14:39.
Reply With Quote
  #6  
Old 13-01-2004, 10:08
d-signer
Guest
 
Posts: n/a
Default

I change export to ai options:

Code:
With expflt 
        .Version = 0 ' FilterAILib.aiVersion7 
        .TextAsCurves = True
        .Platform = 0 ' FilterAILib.aiPC 
        .ConvertSpotColors = False 
        .UseColorProfile = False 
        .SimulateOutlines = False 
        .SimulateFills = False
        .IncludePlacedImages = False
        .IncludePreview = False 
        .Finish 
 End With
With it works better.
Reply With Quote
  #7  
Old 13-01-2004, 10:26
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

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
Reply With Quote
  #8  
Old 13-01-2004, 10:47
d-signer
Guest
 
Posts: n/a
Default

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'
Reply With Quote
  #9  
Old 15-01-2004, 01:32
d-signer
Guest
 
Posts: n/a
Default

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!
Attached Images
 
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 00:35.


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