🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #20587

Re: Vertical tabulation

#20587
From: Mike Mepham
Date: Thu, 13 Jun 2002 10:21
187 lines
7015 bytes
Ole et al, 

Here's my solution to creating vertical tabs by looking for specific paragraph styles in a story. I've extracted it from a much longer script, so it contains only the essentials, except for column turning. Apologies to purists for the messy variable names, etc, but programming is not my day job. The script looks for a pre-formatted ID story in a text frame, and if you are creating such an item as a test, I'd suggest paragraph styles named BodyText, Tab1, Tab2, Tab3, etc. The TabX paragraph styles require indents, left and right in the usual way for vertical tabulation. 

Have to admit that Ole's horizontal tabs solution is much more compact, and if I'd seen it before I wrote this, I'd have probably gone that way in solving my problem. However, this works, and has the advantage of incorporating all the characteristics of paragraph styles, so you may find it useful. 

Option Explicit
 
 Public Sub frames()
 
 Dim DT As InDesign.Application
 Dim DTDoc As InDesign.Document
 Dim DTPage As InDesign.Page
 Dim DTPar As InDesign.Paragraph
 Dim DTStories As InDesign.Stories
 Dim DTStyleList As New Collection
 Dim DTPars As InDesign.Paragraphs
 Dim DTParaStyle As InDesign.ParaStyle
 Dim DTTextContents
 Dim DTTextFrame As InDesign.TextFrame
 Dim vtTextFrame As InDesign.TextFrame
 Dim vtTextLines As InDesign.TextLines
 Dim vtParagraph As InDesign.Paragraph
 Dim vtParaStyle As InDesign.ParaStyle
 
 Dim Y1, Y2, X1, X2
 Dim gbArray
 Dim myListCounter
 Dim myOldPageOrigin
 Dim myRulerOriginReset
 Dim Story
 Dim Items, FrameHeight, Leading, FoundFlag
 Dim SavedY2
 
 Set DT = CreateObject("InDesign.Application.2.0")
 DT.ViewPreferences.VertMeasurementUnits = idMSPoints
 DT.ViewPreferences.HorzMeasurementUnits = idMSPoints
 
 Set DTDoc = DT.ActiveDocument
 Set DTStories = DTDoc.Stories
 Set DTPage = DTDoc.Pages.Item(1)
 Set DTTextFrame = DTPage.TextFrames.Item(1)
 
 If DTStories.Count = 0 Then
     Err.Description = "This publication does not contain any text."
     GoTo myError
 End If
 
 If List1.ListCount = 0 Then
     Err.Description = "You have not added any paragraph styles to the list of paragraph styles."
     GoTo myError
 End If
 Rem The list contains style names, so make a collection of them.
 For myListCounter = 0 To List1.ListCount - 1
     DTStyleList.Add (List1.List(myListCounter))
 Next myListCounter
 
 Rem Set the ruler origin to page, if it isn't already.
 If DTDoc.ViewPreferences.RulerOrigin <> idPageOrigin Then
     myOldPageOrigin = DTDoc.ViewPreferences.RulerOrigin
     DTDoc.ViewPreferences.RulerOrigin = idPageOrigin
     myRulerOriginReset = True
 Else
     myRulerOriginReset = False
 End If
 
 DTDoc.ZeroPoint = Array(0, 0)
 Y1 = DTPage.MarginPreferences.MarginTop
 X1 = DTPage.MarginPreferences.MarginLeft
 Y2 = DTDoc.DocumentPreferences.PageHeight - DTPage.MarginPreferences.MarginBottom
 X2 = DTTextFrame.TextFramePreferences.TextColumnFixedWidth + X1
 For Each Story In DTStories
     Set DTPars = Story.Paragraphs
     FoundFlag = False
     For Each DTPar In DTPars
         If TypeName(DTPar.ParagraphStyle) = "ParaStyle" Then
             Set DTParaStyle = DTPar.ParagraphStyle
             DTTextContents = DTPar.TextContents
             Set vtParaStyle = DTPar.ParagraphStyle
             Set vtTextFrame = DTPage.TextFrames.Add
 
             gbArray = Array(Y1, X1, Y2, X2)
             vtTextFrame.GeometricBounds = gbArray
             vtTextFrame.Contents = DTTextContents
             DTPar.Delete
             
             Set vtParagraph = vtTextFrame.Paragraphs.Item(1)
             vtParagraph.ApplyStyle vtParaStyle
 
             Set vtTextLines = vtTextFrame.TextLines
             Leading = vtParaStyle.Leading
             'other vertical space in the paragraph style should also be added here
             FrameHeight = vtTextLines.Count * Leading
             
             If myFindStyleName(DTParaStyle.StyleName, DTStyleList) Then
                 If FoundFlag = 0 Then
                     Y2 = Y1 + FrameHeight
                     FoundFlag = True
                 End If
                 If Y2 > SavedY2 Then SavedY2 = Y2
                 Y2 = SavedY2
                 gbArray = Array(Y1, X1, Y2, X2)
             Else
                 If FoundFlag = True Then Y1 = SavedY2
                 Y2 = Y1 + FrameHeight
                 FoundFlag = False
                 gbArray = Array(Y1, X1, Y2, X2)
                 Y1 = Y2
             Y2 = DTDoc.DocumentPreferences.PageHeight - Y1
             End If
             vtTextFrame.GeometricBounds = gbArray
         End If
 
     Next DTPar
 Next Story
 
 Exit Sub
 myError:
 MsgBox Err.Description
 End Sub
 
 Private Sub Command1_Click()
 End
 End Sub
 
 Private Sub Command4_Click()
 Dim p
 For p = 0 To List2.ListCount - 1
     If List2.Selected(p) Then List1.AddItem List2.List(p)
 Next p
 End Sub
 
 Private Sub Command5_Click()
 List1.Clear
 GetList
 End Sub
 Function GetList()
 Dim DT As InDesign.Application
 Dim DTDoc As InDesign.Document
 Dim DTParaStyles As InDesign.ParaStyles
 Dim DTCollection As New Collection
 Dim Object As Variant
 Dim p
 
 Set DT = CreateObject("InDesign.Application.2.0")
 
 Rem Check to make sure there are documents open.
 If DT.Documents.Count <> 0 Then
     Set DTDoc = DT.ActiveDocument
     Set DTParaStyles = DTDoc.ParaStyles
     List2.Clear
     If DTParaStyles.Count <> 0 Then
         For Each Object In DTParaStyles
             If Object.StyleName <> "" Then
                 List2.AddItem Object.StyleName
             End If
         Next Object
     End If
 End If
 
 End Function
 
 Private Sub Command3_Click()
 frames
 End Sub
 
 Private Sub Command6_Click()
 List1.Clear
 End Sub
 
 Private Sub Form_Load()
 GetList
 End Sub
 
 Function myFindStyleName(DTParaStyleName, myStyleNamesList)
 Dim myFoundStyleName
 Dim myStyleName
 myFoundStyleName = False
     For Each myStyleName In myStyleNamesList
     If DTParaStyleName = myStyleName Then
         myFoundStyleName = True
         Exit For
     End If
     Next myStyleName
     myFindStyleName = myFoundStyleName
 End Function
 
Technical Details
Message-ID: <ef88d10.12@WebX.aaQKaf7vad4>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-05!supernews.com!feed.textport.net!diablo.netcom.net.uk!netcom.net.uk!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <ef88d10.-1@WebX.aaQKaf7vad4>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,22ddfa026b436769
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2002-06-13 03:38:14 PST
From: "Mike Mepham" <mike.mepham@cluemaster.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-05!supernews.com!feed.textport.net!diablo.netcom.net.uk!netcom.net.uk!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Re: Vertical tabulation
Message-ID: <ef88d10.12@WebX.aaQKaf7vad4>
Date: Thu, 13 Jun 2002 03:21:32 -0700
References: <ef88d10.-1@WebX.aaQKaf7vad4>
Lines: 203
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit