🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #2064

Re: Add is not a funtion (when adding a topic)

#2064
From: Olav_Kvern
Date: Wed, 07 Jan 2009 18:48
83 lines
3683 bytes
Hi Morgan,

If you look at IndexSections in the Object Model Viewer in the ESTK, you'll see that it doesn't have an add method. That's because Index sections are added by InDesign based on the topics in the index. Why not just add a topic? Here's an example that shows how to add a topic and subtopics using the findText method:



//CreateIndexEntry.jsx 
//An InDesign CS4 JavaScript 
// 
//Shows how to create an index, create a topic, create subtopics, and add page references. 
main(); 
function main(){ 
	mySetup(); 
	mySnippet(); 
	myTeardown(); 
} 
function mySnippet(){ 
	var myFoundItem; 
	//Reset find/change text preferences. 
	app.findTextPreferences = NothingEnum.nothing; 
	app.changeTextPreferences = NothingEnum.nothing; 
	app.findTextPreferences.findWhat = "Widget ^?"; 
	//Make an example document. 
	var myDocument = myCreateExampleDocument(); 
	var myIndex = myDocument.indexes.add(0); 
	var myTopic = myIndex.topics.add("Widget"); 
	var mySubtopicA = myTopic.topics.add("A"); 
	var mySubtopicB = myTopic.topics.add("B"); 
	var mySubtopicC = myTopic.topics.add("C"); 
	var myFoundItems = myDocument.findText(); 
	for(var myCounter = myFoundItems.length-1; myCounter >= 0; myCounter --){ 
		myFoundItem = myFoundItems[myCounter]; 
		switch(myFoundItem.characters.item(-1).contents){ 
			case "A": 
				mySubtopicA.pageReferences.add(myFoundItem); 
				break; 
			case "B": 
				mySubtopicB.pageReferences.add(myFoundItem); 
				break; 
			case "C": 
				mySubtopicC.pageReferences.add(myFoundItem); 
				break; 
		} 
	} 
	//Reset find preferences. 
	app.findTextPreferences = NothingEnum.nothing; 
} 
function mySetup(){ 
	var myString = "If you're looking for something to buy, you might consider our Widget A (Part Number: X1234-431, $24.95), " 
	myString += "or Widget B (Part Number: X1-4, $74.95).\r"; 
	myString += "Other options include Widget C (Part Number: X123-43, $135.95) and "; 
	myString += "Widget D (Part Number: X12345-4321, $5.95).\r"; 
	//Create an example document. 
	var myDocument = app.documents.add(); 
	//Create a text frame on page 1. 
	var myTextFrame = myDocument.pages.item(0).textFrames.add(); 
	//Set the bounds of the text frame. 
	myTextFrame.geometricBounds = myGetBounds(myDocument, myDocument.pages.item(0)); 
	//Fill the text frame with example text. 
	myTextFrame.contents = myString; 
} 
function myTeardown(){ 
} 
function myGetBounds(myDocument, myPage){ 
	var myPageWidth = myDocument.documentPreferences.pageWidth; 
	var myPageHeight = myDocument.documentPreferences.pageHeight 
	if(myPage.side == PageSideOptions.leftHand){ 
		var myX2 = myPage.marginPreferences.left; 
		var myX1 = myPage.marginPreferences.right; 
	} 
	else{ 
		var myX1 = myPage.marginPreferences.left; 
		var myX2 = myPage.marginPreferences.right; 
	} 
	var myY1 = myPage.marginPreferences.top; 
	var myX2 = myPageWidth - myX2; 
	var myY2 = myPageHeight - myPage.marginPreferences.bottom; 
	return [myY1, myX1, myY2, myX2]; 
}

Thanks,

Ole
Technical Details
Message-ID: <59b77140.3@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!news2!news.glorb.com!newshub.sdsu.edu!webcrossing
References: <59b77140.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,baead8bc4b72bb6b
X-Google-Attributes: gidf939a,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Olav_Kvern@adobeforums.com
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!news2!news.glorb.com!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.scripting.indesign
Subject: Re: Add is not a funtion (when adding a topic)
Message-ID: <59b77140.3@webcrossing.la2eafNXanI>
Date: Wed, 7 Jan 2009 10:48:39 -0800
References: <59b77140.-1@webcrossing.la2eafNXanI>
Lines: 89
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit