Article View: adobe.scripting.indesign
Article #20576Re: Automating the production of Next Page/Previous Page Hyperlinks
From: Olav Kvern
Date: Wed, 26 Jun 2002 20:45
Date: Wed, 26 Jun 2002 20:45
99 lines
6578 bytes
6578 bytes
Dean--
Well, it *is* part of my job, after all. But thanks!<g>
Here's a VBScript that will put next page/previous page hyperlink buttons on each page of a document. Copy it into a text editor (making certain, as you do, that lines don't get broken/wrapped), then save it with the file extension .VBS. To run the script, double-click the .VBS file. If the file doesn't run at all, you need to download and install the Windows Scripting Host from http://msdn.microsoft.com/downloads/default.asp?URL=/downloads/sample.asp?url=/msdn-files/027/001/733/msdncompositedoc.xml <http://msdn.microsoft.com/downloads/default.asp?URL=/downloads/sample.asp?url=/msdn-files/027/001/733/msdncompositedoc.xml>
Dim myInDesign
Rem In VBScript, use decimal values for InDesign constants
idMSPoints = 2054188905
idPageOrigin = 1380143215
Set myInDesign = CreateObject("InDesign.Application.2.0")
Set myDocument = myInDesign.ActiveDocument
Rem If the current measurement units are not points, set them to points.
If myDocument.ViewPreferences.HorzMeasurementUnits <> idMSPoints Then
����myXUnitsReset = True
����myOldXUnits = myDocument.ViewPreferences.HorzMeasurementUnits
����myDocument.ViewPreferences.HorzMeasurementUnits = idMSPoints
Else
����myXUnitsReset = False
End If
If myDocument.ViewPreferences.VertMeasurementUnits <> idMSPoints Then
����myYUnitsReset = True
����myOldYUnits = myDocument.ViewPreferences.VertMeasurementUnits
����myDocument.ViewPreferences.VertMeasurementUnits = idMSPoints
Else
����myYUnitsReset = False
End If
Rem Set the ruler origin to page origin
myDocument.ViewPreferences.RulerOrigin = idPageOrigin
Rem Set the zero point to the ruler origin
myDocument.ZeroPoint = Array(0, 0)
Rem Get the page width and page height
myPageHeight = myDocument.DocumentPreferences.PageHeight
myPageWidth = myDocument.DocumentPreferences.PageWidth
Rem This script uses triangles for the next/previous page buttons.
Set myPolygonPreferences = myInDesign.PolygonPreferences
myPolygonPreferences.InsetPercentage = 100
myPolygonPreferences.NumSides = 3
Rem myWidth and myHeight set the size of the hyperlink buttons--measurements in points
myWidth = 36
myHeight = 24
Rem myXOffset is the distance from the horizontal center line of the page
myXOffset = 6
Rem myYOffset is the distance from the bottom of the page to the bottom of the triangle
myYOffset = 6
Rem Loop through the pages, adding hyperlinks on each page.
For myPageCounter = 1 To myDocument.Pages.Count
����If myPageCounter = 1 Then
��������myMakePageNext myDocument, myDocument.Pages.Item(myPageCounter), myPageWidth, myPageHeight, myWidth, myHeight, myXOffset, myYOffset
����ElseIf myPageCounter = myDocument.Pages.Count Then
��������myMakePagePrevious myDocument, myDocument.Pages.Item(myPageCounter), myPageWidth, myPageHeight, myWidth, myHeight, myXOffset, myYOffset
����Else
��������myMakePagePrevious myDocument, myDocument.Pages.Item(myPageCounter), myPageWidth, myPageHeight, myWidth, myHeight, myXOffset, myYOffset
��������myMakePageNext myDocument, myDocument.Pages.Item(myPageCounter), myPageWidth, myPageHeight, myWidth, myHeight, myXOffset, myYOffset
����End If
Next
If myXUnitsReset = True Then
����myDocument.ViewPreferences.HorzMeasurementUnits = myOldXUnits
End If
If myYUnitsReset = True Then
����myDocument.ViewPreferences.VertMeasurementUnits = myOldYUnits
End If
Rem - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub myMakePageNext(myDocument, myPage, myPageWidth, myPageHeight, myWidth, myHeight, myXOffset, myYOffset)
idFitWindow =1212437367
Set myPolygon = myPage.Polygons.Add
Rem Push the polygon a bit farther onto the page (this keeps it from ending up on the wrong page in a spread.
myPolygon.Move , Array(12, 12)
myPolygon.Rotate -90
myPolygon.GeometricBounds = Array((myPageHeight - myHeight) - myYOffset, (myPageWidth / 2) + myXOffset, myPageHeight - myYOffset, (myPageWidth / 2) + myWidth + myXOffset)
Set myHyperlinkSource = myDocument.HyperlinkPageItemSources.Add(myPolygon)
Set myHyperlinkDestination = myDocument.HyperlinkPageDestinations.Add
myHyperlinkDestination.DestinationPage = myDocument.Pages.Item(myPage.DocumentOffset + 1)
myHyperlinkDestination.ViewSetting = idFitWindow
Set myHyperlink = myDocument.Hyperlinks.Add(myHyperlinkSource, myHyperlinkDestination)
myHyperlink.Visible = False
End Sub
Rem - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sub myMakePagePrevious(myDocument, myPage, myPageWidth, myPageHeight, myWidth, myHeight, myXOffset, myYOffset)
idFitWindow =1212437367
Set myPolygon = myPage.Polygons.Add
Rem Push the polygon a bit farther onto the page (this keeps it from ending up on the wrong page in a spread.
myPolygon.Move , Array(12, 12)
myPolygon.Rotate 90
myPolygon.GeometricBounds = Array((myPageHeight - myHeight) - myYOffset, (myPageWidth / 2) - (myXOffset + myWidth), myPageHeight - myYOffset, (myPageWidth / 2) - myXOffset)
Set myHyperlinkSource = myDocument.HyperlinkPageItemSources.Add(myPolygon)
Set myHyperlinkDestination = myDocument.HyperlinkPageDestinations.Add
myHyperlinkDestination.DestinationPage = myDocument.Pages.Item(myPage.DocumentOffset - 1)
myHyperlinkDestination.ViewSetting = idFitWindow
Set myHyperlink = myDocument.Hyperlinks.Add(myHyperlinkSource, myHyperlinkDestination)
myHyperlink.Visible = False
End Sub
There's another "outside the box" approach that will work on both platforms--I'll post it in a bit.
Thanks,
Ole
Technical Details
Message-ID:
<ef9252e.8@WebX.aaQKaf7vad4>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-05!sn-xit-06!supernews.com!newsswitch.lcs.mit.edu!logbridge.uoregon.edu!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebXReferences:
<ef9252e.-1@WebX.aaQKaf7vad4>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: f939a,385d1db3f7850ac X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2002-06-26 14:07:56 PST From: "Olav Kvern" <okvern@adobe.com> Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-05!sn-xit-06!supernews.com!newsswitch.lcs.mit.edu!logbridge.uoregon.edu!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX Newsgroups: adobe.scripting.indesign Subject: Re: Automating the production of Next Page/Previous Page Hyperlinks Message-ID: <ef9252e.8@WebX.aaQKaf7vad4> Date: Wed, 26 Jun 2002 13:45:52 -0700 References: <ef9252e.-1@WebX.aaQKaf7vad4> Lines: 131 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit