Copy link to clipboard
Copied
Bonjour à tous,
Je ne parviens plus à créer un index avec CC2017
function addTopic() {
var doc = app.documents[0];
//var monTest = app.selection[0].contents;
var new_topic = doc.indexes[0].topics.add (app.selection[0].contents);
new_topic.pageReferences.add (app.selection[0], PageReferenceType.currentPage);
}
Cette commande me renvoie une erreur !
Merci pour votre aide
Philippe
Copy link to clipboard
Copied
Please always state the exact error message you get. "An error" is totally not helpful.
Apart from that, there are several clear errors I can already spot.
1. Your braces do not match (wrong on line 1).
2. "silence" is not a property I recognize.
3. Didn't look it up but I don't thing "Add" is a known function, because (probably) all standard functions start with a lowercase letter.
Copy link to clipboard
Copied
Bonjour et Merci Jongware pour c'est remarque très juste ...
Voici mon erruer "Object is Invalid"
Je n'ai pas vérifié si j'avais un index !!!! voilà l'erreur.
if (myDoc.indexes.length == 0) {
myDoc.indexes.add ();
}
Merci
Copy link to clipboard
Copied
[Ow -- je suis très désolé! My French lessons are several decades ago and so I tend to hit "Translate" if I'm not sure I get the message. I also did not spot that your original "add" gets 'translated' to "Add", suddenly gaining a capital! So please ignore those remarks.]
Copy link to clipboard
Copied
Hi Jongware,
the OP never used property "silence" with the code.
This is an error of the forum's Translate feature if you go from French to English ( sigh!).
In the original version there is "contents"…
Regards,
Uwe
Copy link to clipboard
Copied
Wow the translation engine is creative, "contents" in french would be litterally "happy people". I can't see how it coud be converted to "silence"
Copy link to clipboard
Copied
Hi Loic,
yes. Funny, isn't it?
Jive must not translate anything that's formatted as code.
But apparently…
( Arrgh!!! )
Regards,
Uwe
Copy link to clipboard
Copied
You are presuming an index exists by using doc.indexes[0]
Are you sure about that ?
function addTopic() {
var doc = app.documents[0];
//Referencing the first index in the collection
var myIndex = doc.indexes[0];
//Trying to resolve the reference and if not found, creates a new index instance
!myIndex.isValid && myIndex = doc.indexes.add();
var new_topic = doc.indexes[0].topics.add (app.selection[0].contents);
new_topic.pageReferences.add (app.selection[0], PageReferenceType.currentPage);
}
addTopic();
Copy link to clipboard
Copied
Exacte Loic