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-12-2004, 17:25
johnlfitz
Guest
 
Posts: n/a
Default NEED HELP ON CORELDRAW SCRIPT. FREE PHOTO CALENDAR IF U CAN!

I am trying to decide what I need to create a script to automate the pictures and text import in a 13 page CorelDraw 12 file (started of life as a MS Publisher file)!

This 13 page file is a photo calendar. The first page has a year preview of all 12 months photos, as well as a calendar title. The next 12 pages (Jan, Feb etc) have a picture at the top 1/3 of the page (the months calendar underneath that), and some text directly underneath it.

What I need to do is have a script that goes and takes the "January.jpg", "February.jpg" etc from the same folder that the .cdr file exists on, and place a copies of the relevant graphic in the first page (the year preview) and on it's relevant month page as well. The pictures (photos) are different for each calendar.

The reason I need a script for this is that I have lots of these calendars to generate (literally 100's), and it's very tedious and way too time consuming to load a default template calendar and then manually go and change all the photos and text in it.

Any ideas? I'd be EXTREMELY grateful if anybody could help me!!!

I'LL GLADLY PRINT OFF A FREE 2005 FAMILY PHOTO CALENDAR TO ANY WHO CAN WORK OUT THE SCRIPT !!!!!! (see https://www.top-gifts.co.uk/shopdata...r1_311x448.gif).

Cheers

John
Reply With Quote
  #2  
Old 08-12-2004, 09:55
johnlfitz
Guest
 
Posts: n/a
Default

Can anybody at least help me with a loop sequence to change the file path for picture objects in a .cdr file ? Or at least how to cycle through pages and identify graphic elements on a page?

Many thanks

John
Reply With Quote
  #3  
Old 08-12-2004, 22:03
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

John,

The implementation will depend on the exact way you really want it to work, but here is a suggestion. Create your template calendar and place a simple rectangles (or other object) in place of your photos.

Open Object Manager or Object Data Manager and give each placeholder rectangle a name - the same as the file name. In this example, let it be just the file name, without the path or extension (assuming .jpg here). E.g. "Cover", "January", "February",...

Save the document and copy the JPEGs to the same folder. Make sure you have all of them there (Cover.jpg, January.jpg, ...).
Then run the following code:

Code:
Sub GenerateCalendar()
    Dim p As Page
    Dim s As Shape
    Dim sPhoto As Shape
    Dim strFile As String
    Dim x As Double, y As Double, w As Double, h As Double
    
    ' Loop through all pages
    For Each p In ActiveDocument.Pages
        p.Activate
        ' Loop through all shapes on a given page
        For Each s In p.Shapes
            If s.Name <> "" Then
                ' Get the size and position of the placeholder
                s.GetBoundingBox x, y, w, h
                ' Import the photo
                strFile = ActiveDocument.FilePath & s.Name & ".jpg"
                ActiveLayer.Import strFile
                Set sPhoto = ActiveShape
                ' Set the placeholder's name to the photo, just in case...
                sPhoto.Name = s.Name
                ' Resize and reposition the photo
                sPhoto.SetBoundingBox x, y, w, h, True, cdrCenter
                ' Place the photo just on top of the placeholder
                sPhoto.OrderFrontOf s
                ' Delete the placeholder shape
                s.Delete
            End If
        Next s
    Next p
End Sub
This should do it. You can do a bit further and have a set of folders with the photos, then have the macro open up the template CDR, process calendars one by one, save the finished calendar into a separate folder and then repeat...
Reply With Quote
  #4  
Old 09-12-2004, 02:39
johnlfitz
Guest
 
Posts: n/a
Default

Alex,
Will try it !!

Thanks ever so much, if this does the job you have quite literally saved my life. I'll let you know if it works (if you want the freebie Photo Calendar forward 12 x photos to me and I'll gladly make it for you).

Thanks again,

John Fitzpatrick
Reply With Quote
  #5  
Old 10-12-2004, 10:38
johnlfitz
Guest
 
Posts: n/a
Default

ALEX - it worked with a bit of tweaking ( I had other object on the pages that I wanted the script to ignore). The code is now:

Sub GenerateCalendar()
Dim p As Page
Dim s As Shape
Dim sPhoto As Shape
Dim strFile As String
Dim x As Double, y As Double, w As Double, h As Double

' Loop through all pages
For Each p In ActiveDocument.Pages
p.Activate
' Loop through all shapes on a given page
For Each s In p.Shapes
If (s.Name = "January" Or s.Name = "February" Or s.Name = "March" Or s.Name = "April" Or s.Name = "May" Or s.Name = "June" Or s.Name = "July" Or s.Name = "August" Or s.Name = "September" Or s.Name = "October" Or s.Name = "November" Or s.Name = "December") Then
' Get the size and position of the placeholder
s.GetBoundingBox x, y, w, h
' Import the photo
strFile = ActiveDocument.FilePath & s.Name & ".jpg"
ActiveLayer.Import strFile
Set sPhoto = ActiveShape
' Set the placeholder's name to the photo, just in case...
sPhoto.Name = s.Name
' Resize and reposition the photo
sPhoto.SetBoundingBox x, y, w, h, True, cdrCenter
' Place the photo just on top of the placeholder
sPhoto.OrderFrontOf s
' Delete the placeholder shape
s.Delete
End If
Next s
Next p
End Sub


...... thanks ever so much !!!!!!

One more question . . . . I extract personalisation data from my web-site back office system for each calendar order: If I was to use Object Manager to 'name' the some .cdr text box fields as below (Calendar_title, January_photo_text etc) how can I add code to read this personalisation text data (from a text file within the same folder as the graphics and .cdr file) from the ':' point up to EOL - pasting the text into the text box until the end:

Calendar_title: Pondside Cottage Calendar 2005
January_photo_text: Pondside Ducks by Ali G
February_photo_text: Sunflowers by Wendy O'Flaherty
March_photo_text: The Terrible 3 by Nigel Davidson
April_photo_text: Middle of Nowhere by Daniel Gorman
May_photo_text: sunset in Venice by Ali G
June_photo_text: A cock or two by Wendy O'Flaherty
July_photo_text: Harry,Conor & Amber by Nigel Davidson
August_photo_text: Safari by Daniel Gorman
September_photo_text: Stanley Road by Ali G
October_photo_text: Wildlife by Daniel Gorman
November_photo_text: The Innocents by Nigel Davidson
December_photo_text: Relaxing by Budding Photographer Joe Gorman

Basically, I want to paste in any text after the space, which after the ':' into the relevant page on the cdr file for all the relevant months.

Thanks in advance.

John Fitzpatrick
Reply With Quote
  #6  
Old 10-12-2004, 15:32
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

John,

It is not all that difficult to do. I would just read in the text file, line by line. Parse each line to find the colon ( : ) character, split it up into two pieces and then build some sort of a list so that I can easily find the actual text using the "field name", that is being able to find "Pondside Cottage Calendar 2005" by searching for "Calendar_Title". There is nothing easier to use than the associative array, AKA Dictionary, from Microsoft Scription Runtime library. It is sort of an array which can be indexed by strings. THat is, you can do something like this:

Code:
Dim d As New Dictionary
d("Language") = "English"
d("Age") = 21
In order to use the Dictionary object, go to Tools>References in VBA and place a checkmark next to "Microsoft Scripting Runtime" library. This should be all you need.

Now, to split the text strings read from the file, you can use functions InStr to find where the color occurs on the line and then use Left and Right or Mid to get the text on the left and right of the colon.

Here is how you do it (I did some other changes to your code too - like instead of having long If... Then statement to check for all the months, I put all the month names in an array and then use Filter function to see if the object name is in the list or not.)

Code:
Sub GenerateCalendar()
    Dim p As Page
    Dim s As Shape
    Dim sPhoto As Shape
    Dim strFile As String
    Dim strLine As String, strObjName As String, strText As String
    Dim x As Double, y As Double, w As Double, h As Double
    Dim PhotoNames As Variant
    Dim nPos As Integer
    
    Dim Captions As New Scripting.Dictionary
    ' Read in the picture caption text from a text file first
    strFile = ActiveDocument.FilePath & "Captions.txt"
    Open strFile For Input As #1
    While Not EOF(1)
        Line Input #1, strLine
        strLine = Trim$(strLine)
        nPos = InStr(strLine, ": ")
        If nPos <> 0 Then
            strObjName = Left$(strLine, nPos - 1)
            strText = Mid$(strLine, nPos + 2)
            ' Add the object name/caption text pair to the dictionary
            Captions.Add strObjName, strText
        End If
    Wend
    Close #1
    
    PhotoNames = Array("January", "February", "March", "April", "May", "June", "July", _
                       "August", "September", "October", "November", "December")

    ' Loop through all pages
    For Each p In ActiveDocument.Pages
        p.Activate
        ' Loop through all shapes on a given page
        For Each s In p.Shapes
            If s.Name <> "" Then
                ' See if this object is one of the photo place holders...
                If UBound(Filter(PhotoNames, s.Name, True, vbTextCompare)) >= 0 Then
                    ' Get the size and position of the placeholder
                    s.GetBoundingBox x, y, w, h
                    ' Import the photo
                    strFile = ActiveDocument.FilePath & s.Name & ".jpg"
                    ActiveLayer.Import strFile
                    Set sPhoto = ActiveShape
                    ' Set the placeholder's name to the photo, just in case...
                    sPhoto.Name = s.Name
                    ' Resize and reposition the photo
                    sPhoto.SetBoundingBox x, y, w, h, True, cdrCenter
                    ' Place the photo just on top of the placeholder
                    sPhoto.OrderFrontOf s
                    ' Delete the placeholder shape
                    s.Delete
                ElseIf s.Type = cdrTextShape Then
                    ' If not, it could be a text caption
                    ' Get the text for the associated object name
                    strText = Captions(s.Name)
                    If strText <> "" Then
                        s.Text.Story = strText
                    End If
                End If
            End If
        Next s
    Next p
End Sub
I hope this helps
Reply With Quote
  #7  
Old 06-06-2008, 19:45
LaffRiot
Guest
 
Posts: n/a
Default

Very nice concept.

I have tried to run the sample code after setting up all of the objects and files, however the VBA editor keeps flagging this line:

strFile = ActiveDocument.FilePath & s.Name & ".jpg"

My error says "compile error","expected end of statement", highlighting the ; at the end of $amp;

I have tried running this in both c11 & cx3 and get the same error.
I am taking a guess that I do not have the correct reference set loaded - muddling my way through as this is my first peek at VBA - any help appreciated

Last edited by LaffRiot; 06-06-2008 at 20:21. Reason: 2nd guess
Reply With Quote
  #8  
Old 06-06-2008, 22:24
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,769
Blog Entries: 9
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Error

The &amp is from the transition of the forum, some of the code did not translate nicely.....so you need your line to look like this:
Code:
strFile = ActiveDocument.FilePath & s.Name & ".jpg"
Hope that helps,

-Shelby
Reply With Quote
  #9  
Old 06-06-2008, 22:59
LaffRiot
Guest
 
Posts: n/a
Default

!!!!!!!!!!!!!!!!!!!!!!!

cool.

so cool.

ty - it works!
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
Script through CorelDRAW and CorelPHOTO-PAINT d-signer Corel Photo-Paint VBA 3 14-01-2004 08:55
New Macro / script for CorelDraw V. x acaputo1 New product ideas 4 31-08-2003 13:43
Curve2Line script ! jobar CorelDRAW/Corel DESIGNER VBA 1 14-08-2003 11:40
CorelDraw eating up memory dcsquare CorelDRAW/Corel DESIGNER VBA 1 06-06-2003 09:47


All times are GMT -5. The time now is 08:19.


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