Article View: adobe.scripting.indesign
Article #19574Re: Auto Numbering
From: Dave Saunders
Date: Fri, 06 Dec 2002 15:09
Date: Fri, 06 Dec 2002 15:09
58 lines
3213 bytes
3213 bytes
Here's another version of the script that works by context. This time, list the paragraph styles you want ignored (if any).
property ignoreThese : {"StyleName", "AnotherStyle"}
-- this script auto-numbers paragraphs to a depth of three
-- based on the content of the paragraphs up to the first space
-- paragraphs using styles listed in the property are ignored
-- paragraphs with no spaces are ignored
set oldDelims to AppleScript's text item delimiters
tell application "InDesign 2.0.2"
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 AppleScript's text item delimiters to {" "}
set myStyle to name of applied paragraph style of paragraph n of myStory
if myStyle is not in ignoreThese then
set theText to contents of paragraph n of myStory
set theParts to every text item of theText
if contents of item 1 of theParts is not equal to theText then
-- paragraph has at least one space
set AppleScript's text item delimiters to {"."}
set theLevel to count of text items of item 1 of theParts
if theLevel = 1 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 theLevel = 2 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 theLevel = 3 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 if
end repeat
end tell
set AppleScript's text item delimiters to oldDelims
There are ways of dealing with splitting the document as you've done. For instance, if the number of the section is in the document title, then the script can get the number from the document name and use that to seed the initial value of topcount.
I think you're going to have to learn some scripting, but this job is not that hard now I've given you this start.
Dave
Technical Details
Message-ID:
<1de6d01c.11@WebX.la2eafNXanI>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!news2.euro.net!195.129.110.4.MISMATCH!lnewspeer00.lnd.ops.eu.uu.net!emea.uu.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-06 07:37:50 PST From: "Dave Saunders" <daves@pdsassoc.com> Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!news2.euro.net!195.129.110.4.MISMATCH!lnewspeer00.lnd.ops.eu.uu.net!emea.uu.net!newsfeed01.sul.t-online.de!t-online.de!WebX Newsgroups: adobe.scripting.indesign Subject: Re: Auto Numbering Message-ID: <1de6d01c.11@WebX.la2eafNXanI> Date: Fri, 6 Dec 2002 07:09:05 -0800 References: <1de6d01c.-1@WebX.la2eafNXanI> Lines: 61 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit