8 Replies Latest reply on Apr 13, 2017 4:35 AM by [Jongware]

    [JS] CC2017 .topics.add

    Liphou Level 1

      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

        • 1. Re: [JS] CC2017 .topics.add
          [Jongware] Most Valuable Participant

          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.

          • 2. Re: [JS] CC2017 .topics.add
            Liphou Level 1

            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

            • 3. Re: [JS] CC2017 .topics.add
              Loic.Aigon Adobe Community Professional

              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();
              
              • 4. Re: [JS] CC2017 .topics.add
                Laubender Adobe Community Professional & MVP

                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

                • 5. Re: [JS] CC2017 .topics.add
                  Liphou Level 1

                  Exacte Loic

                  • 6. Re: [JS] CC2017 .topics.add
                    Loic.Aigon Adobe Community Professional

                    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"

                    • 7. Re: [JS] CC2017 .topics.add
                      Laubender Adobe Community Professional & MVP

                      Hi Loic,

                      yes. Funny, isn't it?
                      Jive must not translate anything that's formatted as code.
                      But apparently…
                      ( Arrgh!!! )

                       

                      Regards,
                      Uwe

                      • 8. Re: [JS] CC2017 .topics.add
                        [Jongware] Most Valuable Participant

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