Thread View: adobe.scripting.indesign
6 messages
6 total messages
Started by Morgan_Routledge
Tue, 06 Jan 2009 22:41
Add is not a funtion (when adding a topic)
Author: Morgan_Routledge
Date: Tue, 06 Jan 2009 22:41
Date: Tue, 06 Jan 2009 22:41
3 lines
1206 bytes
1206 bytes
app.documents[0].indexes[0].indexSections.item(2).topics.add(); returns with 'is not a function'. I'm not sure if this is a bug but for the life of me, I can't call that method. app.documents[0].indexes[0].indexSections.item(2).topics.count() is vaild and returns with an integer and app.documents[0].indexes[0].indexSections.item(2).topics.constructor.name returns 'topics' so I know i'm in the right context. Does anyone have any insight? To give you a little more information, I am trying to create an index from a word list but i'm running into problems creating a new topic entry.
Re: Add is not a funtion (when adding a topic)
Author: Morgan_Routledge
Date: Wed, 07 Jan 2009 05:04
Date: Wed, 07 Jan 2009 05:04
1 lines
847 bytes
847 bytes
I understand that topics.add() is called with arguments but it still halts on add is not a function. I can call other functions like count() and I've used add() for other objects. Has anyone ever tried to script the creation of a index?
Re: Add is not a funtion (when adding a topic)
Author: Martin Fischer
Date: Wed, 07 Jan 2009 05:41
Date: Wed, 07 Jan 2009 05:41
6 lines
921 bytes
921 bytes
Hi Morgan, take a look at an example of Peter Kahrel in <http://www.hilfdirselbst.ch/foren/Indizierung_automatisieren_P270961.html#270961> or at another example (IndexFromList_CS3.jsx) in <http://www.hilfdirselbst.ch/foren/Skript_zum_Index_generieren_P322824.html#322824> Martin Fischer
Re: Add is not a funtion (when adding a topic)
Author: Morgan_Routledge
Date: Wed, 07 Jan 2009 16:58
Date: Wed, 07 Jan 2009 16:58
1 lines
791 bytes
791 bytes
Thanks Martin, I'll give that a try. I've found it hard finding resources for scripting indesign, I appreciated the help. Is there a large Germain community for scripting indesign?
Re: Add is not a funtion (when adding a topic)
Author: Olav_Kvern
Date: Wed, 07 Jan 2009 18:48
Date: Wed, 07 Jan 2009 18:48
83 lines
3683 bytes
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
Re: Add is not a funtion (when adding a topic)
Author: Morgan_Routledge
Date: Wed, 14 Jan 2009 17:25
Date: Wed, 14 Jan 2009 17:25
1 lines
655 bytes
655 bytes
I was able to get my script working. Thanks Ole and Marin.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads