Skip to main content
Liphou
Inspiring
April 13, 2017
Question

[JS] CC2017 .topics.add

  • April 13, 2017
  • 2 replies
  • 575 views

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

This topic has been closed for replies.

2 replies

Loic.Aigon
Legend
April 13, 2017

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();

Liphou
LiphouAuthor
Inspiring
April 13, 2017

Exacte Loic

Jongware
Community Expert
Community Expert
April 13, 2017

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.

Liphou
LiphouAuthor
Inspiring
April 13, 2017

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

Jongware
Community Expert
Community Expert
April 13, 2017

[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.]