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 19-01-2004, 11:25
venturian
Guest
 
Posts: n/a
Default File Converter - turning off layers

Is it possible to adapt the CorelDraw 11 file converter script to turn off layers. I assume that as the Export,
ExportBitmap, and ExportEx functions deal in document objects not layer objects it cant be done...

I'm trying to convert ~5000 files (vr 8-11) to jpg and most have a number of layers turned off so it would be v.handy.

Cheers
Reply With Quote
  #2  
Old 19-01-2004, 11:44
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: File Converter - turning off layers

I'm not quite sure what you need. If I can guess, you have a lot of documents with hidden layers but you want to export them so that the objects on those layers are still present in the exported file. Is that correct?

If so, then it can be done quite easily. After each document is open, you just need to add a code similar to this:

Code:
For Each p In ActiveDocument.Pages
    For Each lr In p.Layers
        If Not lr.Visible Then lr.Visible = True
    Next lr
Next p
provided that these two variables are declared at the top of the function:

Code:
Dim lr As Layer
Dim p As Page
This will go through all layers on all pages and will make them all visible.

Ok, here is what you need to do:

- Open VBA and find a project FileConverter (FileConverter.gms)
- Drill down the tree to Forms>frmFileConverter in Project Explorer (Ctrl-R)
- Right click on this node and select "View Code" from the popup menu
- Search for a subroutine called "ConvertFiles()"
- It already has the page variable p declared, so you just need to add "Dim lr As Layer" right below all the other DIM statements at the top of the subroutine
- Scroll a little down the source code and you will see this:
Code:
        If PageAsSeparateFile And UCase$(Right$(CurFileName, 4)) = ".CDR" Then
            Set d = OpenDocument(CurFileName)
        Else
            Set d = CreateDocument
            d.ActiveLayer.Import CurFileName, , si
        End If
Add the following code right after the above snipped:

Code:
        For Each p In ActiveDocument.Pages
            For Each lr In p.Layers
                If Not lr.Visible Then lr.Visible = True
            Next lr
        Next p
And this should do the trick.
Reply With Quote
  #3  
Old 19-01-2004, 12:24
venturian
Guest
 
Posts: n/a
Default Re: File Converter - turning off layers

Alex, I've got a lot of documents with hidden layers and I want to keep them hidden. At the moment, when I convert them using the file converter the hidden layers appear. Do you not find this problem?
Reply With Quote
  #4  
Old 19-01-2004, 12:33
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: File Converter - turning off layers

Oh, that's very easy to fix. In fact, Export as well as printing, cares less for the visibility of the layer. What matters is whether the layer is printable. If the layer is printable, its contents will be exported, even though the layer may be invisible.

So, the workaround would be to go through the layers and see if they are hidden but printable, make them non-printable. Everything said above stays the same, except the very last piece of code to add to the file converter after the document is open:

Code:
        For Each p In ActiveDocument.Pages
            For Each lr In p.Layers
                If lr.Visible <> lr.Printable Then lr.Printable = lr.Visible
            Next lr
        Next p
Basically what the above code does is it makes sure that the Printable option is always in sync with Visible.
Reply With Quote
  #5  
Old 20-01-2004, 05:57
venturian
Guest
 
Posts: n/a
Default Re: File Converter - turning off layers

I still cannot get file converter to not convert non-printable layers.

I've changed the code to

Code:
        If PageAsSeparateFile And UCase$(Right$(CurFileName, 4)) = ".CDR" Then
            Set d = OpenDocument(CurFileName)
        Else
            Set d = CreateDocument
            d.ActiveLayer.Import CurFileName, , si
        End If
    For Each p In ActiveDocument.Pages
        For Each lr In p.Layers
            If lr.Visible <> lr.Printable Then lr.Printable = lr.Visible
        Next lr
    Next p
( sorry if its wrong, its my 2nd day of VBA)

I'm trying this out with the attached test image. If I use File-Export it creates the jpg correctly i.e. only layer 1. If I use file converter (with the above code) it creates a jpg with layer 1 and the non-visible/non-printable layer 2 as well. Do you get the same result?
Attached Files
File Type: cdr layer_test.cdr (13.4 KB, 418 views)
Reply With Quote
  #6  
Old 26-01-2004, 10:42
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: File Converter - turning off layers

You are right, there is another problem with the macro. When it just process file, it creates a new blank document, imports a file, then exports everything. However when a CDR file with hidden and/or unprintable layers is imported, the hidden objects are imported as well, and therefore they appear in the document. Regular import puts everything as one group and all the layers and pages are lost. Therefore there is nothing the macro can do to hide the former invisible objects because the visibility information is lost during the import.

There is one workaround though. When you use "Export each page", it uses OPEN for CDR files, rather than IMPORT. And this can be worked through. I have also discovered another problem with the macro that makes it not to export files which have only 1 page when using Export each page option.

I have fixed all those quirks and I'm attaching the updated GMS file for you, so you don't have to fiddle with all those changes yourself.

Give it a try and let me know what you think.
Attached Files
File Type: zip FileConverter.zip (94.0 KB, 518 views)
Reply With Quote
  #7  
Old 27-01-2004, 09:08
venturian
Guest
 
Posts: n/a
Default Re: File Converter - turning off layers

Alex,

I got an error message

Compile Error: Variable not Defined

When I edit the VBA it opens at

Code:
Case DES_FILE
            GetFilterType = cdrDES
Is the error because I dont have Designer?

If I comment out these 2 lines everything else works perfectly. Thanks a lot.
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
File converter suggestion vallentin Macros/Add-ons 6 28-09-2005 21:50
File Converter script error CorelDummy CorelDRAW/Corel DESIGNER VBA 2 25-01-2005 09:38
SOME CHANGES OVER FILE CONVERTER olympiatr CorelDRAW/Corel DESIGNER VBA 2 14-04-2004 03:05
Open - Resize - Savefile in Photo Paint greenee Corel Photo-Paint VBA 2 28-06-2003 04:54
Problem with File Converter CMX->EPS starless Macros/Add-ons 4 09-05-2003 09:33


All times are GMT -5. The time now is 16:25.


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