🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #19901

Re: Database Driven Catalog - ???

#19901
From: maxdunn
Date: Thu, 14 Nov 2002 03:38
87 lines
4751 bytes
And about your alignment question, here is a slight modification to the previous example. To run this: 
open Access and create a new module. In the VBA view, set two references: choose Tools\References and: 
1. Uncheck the ADO reference 
2. Scroll down and check Adobe InDesign Type Library 
3. Scroll down and check Microsoft DAO Object Library (whatever your latest version is, mine is 3.6 and I think that's the last one) 

Make a simple table "tblMyTable" with fields "MyField1" and "MyField2" and put in some dummy text. 

Then paste the following in the module: 

Dim oPrevTextFrame 
Public Function SetupPage(oPage, iPage) As InDesign.TextFrame 
    Rem Make the X textboxes on a new page 
    Rem Takes the page object and the page number 
    Rem returns the first textbox on the page 
    Set oDocument = oPage.Parent.Parent 
    iColumns = oPage.MarginPreferences.ColumnCount 
    dPageWidth = oDocument.DocumentPreferences.PageWidth 
    dPageHeight = oDocument.DocumentPreferences.PageHeight 
    dGutter = oPage.MarginPreferences.ColumnGutter 
    If iPage Mod 2 = 0 Then 
        dMarginRight = oPage.MarginPreferences.MarginLeft 
        dMarginLeft = oPage.MarginPreferences.MarginRight 
    Else 
        dMarginRight = oPage.MarginPreferences.MarginRight 
        dMarginLeft = oPage.MarginPreferences.MarginLeft 
    End If 
    dMarginTop = oPage.MarginPreferences.MarginTop 
    dMarginBottom = oPage.MarginPreferences.MarginBottom 
    Rem Get the coordinates of the textbox: 
    Rem 1st one: 
    Rem X1 is MarginLeft 
    Rem Y1 is MarginTop 
    Rem X2 is MarginLeft + ColumnWidth 
    Rem Y2 is PageHeight - MarginBottom 
    Rem Figure out Column Width... 
    dColumnWidth = (dPageWidth - (dMarginRight + dMarginLeft) _ 
        - (dGutter * (iColumns - 1))) / iColumns 
    Rem Y coordinates stay the same no matter what column 
    dY1 = dMarginTop 
    dY2 = dPageHeight - dMarginBottom 
    For i = 1 To iColumns 
        dOffset = (i - 1) * (dColumnWidth + dGutter) 
        dX1 = dMarginLeft + dOffset 
        dX2 = dX1 + dColumnWidth 
        Set oTextFrame = oPage.TextFrames.Add 
        If Not (oPrevTextFrame Is Nothing) Then 
            Set oPrevTextFrame.NextTextFrame = oTextFrame 
        End If 
        oTextFrame.GeometricBounds = Array(dY1, dX1, dY2, dX2) 
        Set oPrevTextFrame = oTextFrame 
        If i = 1 Then 
            Set SetupPage = oTextFrame 
        End If 
    Next 
End Function 
Public Function Output() 
    Dim db As DAO.Database 
    Dim rs As DAO.Recordset 
    Set db = CurrentDb 
    Set rs = db.OpenRecordset("tblMyTable", dbOpenDynaset) 
    Rem Make Document-level objects 
    Dim oInDesign As InDesign.Application 
    Set oInDesign = CreateObject("InDesign.Application.2.0") 
    Set oDocument = oInDesign.Documents.Add 
    Set oPage = oDocument.Pages.Item(1) 
    Rem note that you can check overflow conditions 
    Rem and add more pages/textframes as you go 
    Set oPrevTextFrame = Nothing 
    Set oTextFrame = SetupPage(oPage, 1) 
    Do While Not rs.EOF 
        sBuf1 = rs!myField1 
        sBuf2 = rs!myField2 
        oTextFrame.InsertionPoints.Item(-1).TextContents = sBuf1 _ 
            & vbTab & sBuf2 & vbCr 
            Rem vbcrlf = carriage return/linefeed 
            Rem vbcr = carriage return (new para/line) 
            Rem vblf = linefeed (same para new line) 
        rs.MoveNext 
    Loop 
    rs.Close 
    Set rs = Nothing 
End Function 

To run it, click anywhere in the "Output()" function and click the Play button on the toolbar. Should make text boxes for whatever number of columns you have set in your preferences. 

This is a more modular approach: when you need a new page, you can call a function like this. Note that the oPrevTextFrame variable is declared outside of either function so it can be called from either, or from SetupPage() when it sets up a subsequent page.
Technical Details
Message-ID: <1de69529.8@WebX.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!easynet-quince!mango.news.easynet.net!easynet.net!proxad.net!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <1de69529.-1@WebX.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,4348409c0a586298
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2002-11-13 20:16:04 PST
From: maxdunn <maxdunn@siliconpublishing.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!easynet-quince!mango.news.easynet.net!easynet.net!proxad.net!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Re: Database Driven Catalog - ???
Message-ID: <1de69529.8@WebX.la2eafNXanI>
Date: Wed, 13 Nov 2002 19:38:06 -0800
References: <1de69529.-1@WebX.la2eafNXanI>
Lines: 96
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit