🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #18876

Re: use master page

#18876
From: Olav Kvern
Date: Fri, 14 Feb 2003 17:55
67 lines
3383 bytes
Laurent--

Sorry, I was going to post the thread containing my function here, but I'm having a hard time finding the thread. Here's the subroutine I was talking about:



Private Sub Command1_Click() 
Dim myInDesign As InDesign.Application 
Dim myMasterSpread As InDesign.MasterSpread 
Dim myPage As InDesign.Page 
Set myInDesign = CreateObject("InDesign.Application.2.0") 
Set myDocument = myInDesign.Documents.Add 
Set myMasterSpread = myDocument.MasterSpreads.Item("A-Master") 
Rem Delete one of the master spread's pages 
myMasterSpread.Pages.Item(1).Delete 
Set myPage = myMasterSpread.Pages.Item(1) 
Rem Add four random rectangles to the page. 
myPageHeight = myDocument.DocumentPreferences.PageHeight 
myPageWidth = myDocument.DocumentPreferences.PageWidth 
For myCounter = 1 To 8 
    myX1 = myPageWidth * Rnd 
    myX2 = myPageWidth * Rnd 
    myY1 = myPageHeight * Rnd 
    myY2 = myPageHeight * Rnd 
    Set myRectangle = myPage.Rectangles.Add 
    myRectangle.GeometricBounds = Array(myY1, myX1, myY2, myX2) 
    Rem Label and color one of the rectangles. 
    If myCounter = 4 Then 
        myRectangle.FillColor = myDocument.Swatches.Item("Black") 
        myRectangle.Label = "Delete this one" 
    End If 
Next 
Set myMasterSpread = myDocument.MasterSpreads.Add 
myMasterSpread.Pages.Item(1).AppliedMaster = myDocument.MasterSpreads.Item("A-Master").Pages.Item(1)

Set myPage = myDocument.Pages.Item(1) 
myPage.AppliedMaster = myMasterSpread

myIndex = myFindMasterItemByLabel(myPage.AppliedMaster, "Delete this one") 
If myIndex = Empty Then 
    myIndex = myFindMasterItemByLabel(myPage.AppliedMaster.AppliedMaster, "Delete this one") 
End If 
myPage.MasterPageItems.Item(myIndex).Delete 
Rem Choose Remove All Local Overrides from the Pages palette menu to see 
Rem the overridden rectangle reappear. 
End Sub 
Private Function myFindMasterItemByLabel(myMasterPage, myLabel) 
For myCounter = 1 To myMasterPage.PageItems.Count 
    If myMasterPage.PageItems.Item(myCounter).Label = myLabel Then 
        Rem The index of the item is the count of the item from the end of the list, 
        Rem because PageItems are arranged in back-to-front order. But the MasterPageItems 
        Rem collection for a page is indexed in the opposite order. So we have to return 
        Rem the index using the following technique: 
        myFindMasterItemByLabel = (myMasterPage.PageItems.Count - myCounter) + 1 
        Exit Function 
    End If 
Next 
End Function 




The above demonstrates finding a master page item by its label--you could use other attributes, such as color, page position, etc.

Thanks,

Ole
Technical Details
Message-ID: <1de7b559.7@WebX.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!newsfeed.gamma.ru!Gamma.RU!newsfeed.tpinternet.pl!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <3E4113E8.1060604@comidoc.fr>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,ff1d5253cfa97279
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-02-14 10:08:10 PST
From: "Olav Kvern" <okvern@adobe.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!newsfeed.gamma.ru!Gamma.RU!newsfeed.tpinternet.pl!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Re: use master page
Message-ID: <1de7b559.7@WebX.la2eafNXanI>
Date: Fri, 14 Feb 2003 09:55:53 -0800
References: <3E4113E8.1060604@comidoc.fr>
Lines: 74
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit