Article View: adobe.scripting.indesign
Article #19609Re: Auto Numbering
From: Dave Saunders
Date: Mon, 02 Dec 2002 20:42
Date: Mon, 02 Dec 2002 20:42
58 lines
3230 bytes
3230 bytes
This should get you started. It does no syntax error checking of the paragraphs that puport to be heads, so if they're not in the format you descrbe, well, either look out, or add some syntax checking to the script.
By the way, it works on the whole story and assumes that the starting top number is 1.
Before using it, change the names of the heads in the three properties at the top. You can have as many different head styles at each level as you need, as I've tried to indicate with this example. It all the heads at a particular level are of the same style (as in secondheads here) then just have one style name in the list.
property topheads : {"H1", "H1alt"}
property secondheads : {"H2"}
property thirdheads : {"H3", "H3alt"}
-- this script auto-numbers headings to a depth of three
-- first, concatenate all head styles so other paras are
-- easily ignored
copy topheads to allheads
repeat with n from 1 to count of secondheads
copy item n of secondheads to end of allheads
end repeat
repeat with n from 1 to count of thirdheads
copy item n of thirdheads to end of allheads
end repeat
tell application "InDesign 2.0.1"
set myStory to parent story of selection
set theLim to count of paragraphs of myStory
set topCount to 1
set secondCount to 1
set thirdCount to 1
repeat with n from 1 to theLim
set myStyle to name of applied paragraph style of paragraph n of myStory
if myStyle is in allheads then
if myStyle is in topheads then
set word 1 of paragraph n of myStory to topCount as string
set topCount to topCount + 1
set secondCount to 1
set thirdCount to 1
else if myStyle is in secondheads then
set word 1 of paragraph n of myStory to (topCount - 1) as string
set word 2 of paragraph n of myStory to secondCount as string
set secondCount to secondCount + 1
set thirdCount to 1
else if myStyle is in thirdheads then
set word 1 of paragraph n of myStory to (topCount - 1) as string
set word 2 of paragraph n of myStory to (secondCount - 1) as string
set word 3 of paragraph n of myStory to thirdCount as string
set thirdCount to thirdCount + 1
end if
end if
end repeat
end tell
Note that if you label something as a level three head but it doesn't start with n.m.p. you'll get a bad result. Indeed, if you have a third level head that doesn't have three words in it (each number counts as a word), the script will give an error.
Dave
Technical Details
Message-ID:
<1de6d01c.2@WebX.la2eafNXanI>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.news2me.com!newsfeed.freenet.de!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebXReferences:
<1de6d01c.-1@WebX.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,e7d83a70f4be8fa9 X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2002-12-02 13:07:48 PST From: "Dave Saunders" <daves@pdsassoc.com> Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.news2me.com!newsfeed.freenet.de!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX Newsgroups: adobe.scripting.indesign Subject: Re: Auto Numbering Message-ID: <1de6d01c.2@WebX.la2eafNXanI> Date: Mon, 2 Dec 2002 12:42:37 -0800 References: <1de6d01c.-1@WebX.la2eafNXanI> Lines: 65 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit