🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #14809

Re: (AS, CS) Relating page references to index subtopics

#14809
From: Cris_Lawrence
Date: Mon, 12 Jan 2004 14:36
43 lines
3461 bytes
Peter:

Thanks to your examples and a little persistence, I solved my problem. But I am not satisfied with the solution as it takes a brute force approach to obtain a property that should ordinarily be readily available. Here's the crux of my javascript:

var myDocument = app.documents.item(0);
with(myDocument) {
    var myIndexOptions = indexGenerationOptions;
    myIndexOptions.title = "Product Index"
    myIndexOptions.includeHiddenEntries = true;
    myIndexOptions.includeBookDocuments = true;
    myIndexOptions.level1Style = "Index Level 1";
    myIndexOptions.level2Style = "Index Level 2";
    var myIndex = indexes.add();
    var myKeywordLayer = layers.item("Keywords");
    var myTextFrameList = myKeywordLayer.textFrames;
    for (i = 0; i < myKeywordLayer.textFrames.length; i++ ) {
        var myTextFrame = myTextFrameList.item(i);
        var myParentStory = myTextFrame.parentStory
        var myEntryList = myTextFrame.contents
        if(myEntryList.length > 0) {
            var myEntries = parseIndexEntries(myEntryList);
            for(j = 0; j < myEntries.length; j++ ) {
                var myComponents = parseEntryComponents(myEntries[j]);
                var myTopic = myIndex.topics.add(myComponents[0]);
                if( myComponents.length > 1) {
                    var mySubtopic = myTopic.subtopics.add(myComponents[1]);
                    for( k = 0; k < myIndex.topics.length; k++ ) {
                        if( myIndex.topics[k].subtopics.length > 1 && myIndex.topics[k].subtopics[1].name == myComponents[1] ) {
                            myTopic = myIndex.topics[k];
                            break;
                        }
                    }
                }
                var myPageReference = myTopic.pageReferences.add(myParentStory,0,PageReferenceType.currentPage);
            }
        }
    }
    var myIndexesLayer = layers.item("Indexes");
    var myIndexPage = pages.add(LocationOptions.atEnd);
    myIndex.generate(myIndexPage,[3,3], myIndexesLayer);
}

The two parsing handlers mentioned merely separate index entries and topic and subtopic within an index entry using tokens. myComponents[0] represents the main topic and myComponents[1] (where it exists) represents the subtopic. Notice my roundabout way of collecting the parent of the subtopic (i.e., the k loop). I tried mySubtopic.parent, which would be the ideal way to collect the information I need, but this statement results in an 'Invalid Object' error. In fact, I can't seem to access any of the properties of mySubtopic. If anyone sees a better workaround, please share. This extra looping may be prohibitively costly since this index procedure will ultimately have to scale up to handle a 2500+ page catalog.
Technical Details
Message-ID: <2ccf3c88.6@webx.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!webx
References: <2ccf3c88.-1@webx.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,ee2b3c498d942059
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2004-01-12 06:37:46 PST
From: Cris_Lawrence@adobeforums.com
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!webx
Newsgroups: adobe.scripting.indesign
Subject: Re: (AS, CS) Relating page references to index subtopics
Message-ID: <2ccf3c88.6@webx.la2eafNXanI>
Date: Mon, 12 Jan 2004 06:36:34 -0800
References: <2ccf3c88.-1@webx.la2eafNXanI>
Lines: 59
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit