🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #16757

ApplyStyle Method (Semi-Newbie Question)

#16757
From: Paul Jurgens
Date: Thu, 31 Jul 2003 15:45
40 lines
2652 bytes
I am just getting started on creating scripts for my own use in InDesign (2.0.2) using my rusty "old" BASIC and LotusScript skills.

I created a small VB script that cycles through each story and checks the style on each paragraph. When it finds the target style (Task Columns), it checks the first character. If the first character is a horizontal tab, it applys a character style (Lines) to the tab so that the tab will be underlined. This is used as a grading line for how well a student has accomplished a task on a lesson sheet when printed.

The script works fine now as written below:

Dim myInDesign
Set myInDesign = CreateObject("InDesign.Application.2.0")
Set myDocument = myInDesign.ActiveDocument

REM Count the stories
numStories = myDocument.Stories.Count

REM Cycle through stories
For s = 1 To numStories
    Set myStory = myDocument.Stories.Item(s)

REM Count the paragraphs
    numParas = myStory.Paragraphs.Count

REM Cycle through paragaraphs and check style
    For p = 1 To numParas
        Set myParagraph = MyStory.Paragraphs.Item(p)
        Set myStyle = myParagraph.ParagraphStyle

REM If correct style, get the first character
        If myStyle.Name = "Task Columns" Then
            Set myFirstChar = myParagraph.Characters.Item(1)

REM If first character is a tab then apply character style
            If myFirstChar.TextContents = Chr(9) Then
                 myFirstChar.CharacterStyle = myDocument.CharStyles.Item("Lines")
            End If
        End If
    Next
Next

Originally, I had tried to use the ApplyStyle method for the line near the end which actually applies the character style. While the way that I wrote it works, I am trying to find the appropriate syntax for the ApplyStyle method for my own education. I have looked in the scripting guide and tried it several ways but could not get it to work using the method. Any suggestions?

Paul Jurgens
Technical Details
Message-ID: <1dea2561.-1@WebX.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.arcor-online.net!newsfeed01.sul.t-online.de!t-online.de!WebX

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,79e1d7a74e4853d1,start
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-07-31 09:08:13 PST
From: "Paul Jurgens" <flynfall@yahoo.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.arcor-online.net!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: ApplyStyle Method (Semi-Newbie Question)
Message-ID: <1dea2561.-1@WebX.la2eafNXanI>
Date: Thu, 31 Jul 2003 08:45:47 -0700
Lines: 52
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit