5 Replies Latest reply on Jun 3, 2015 9:48 PM by sethkhouri

    need help making a label




      I am really really new to scripting, I have edited an existing javascript (and its doing most of what i need it to do) except I now need to combine the Document name meDocument.name and page number app.activeWindow.activePage.name into myLabel. but I can not get it to do that.

      also the document name is made up a numbers and letters, I only want the numbers in the label.


      For example

      the doc is called BTAS2756.indd and the page number is 17. I want the label to be 2756_17


      can anyone help me with this?


      thank you very much.



        • 1. Re: need help making a label
          Marc Autret Level 5

          Hi Seth,


          You need probably something like this:


          // Given myDoc and myPage
          // ---
          var myLabel = myDoc.properties.name.replace(/\D+/,'')
                        + '_' + myPage.name;
          // Check
          // ---
          alert( myLabel );




          • 2. Re: need help making a label
            sethkhouri Level 1

            Thanks Marc.


            That worked a treat, I was so close...


            One last question the myDoc.properties.name also brings in the file ext .indd, how do i get rid of the .indd?





            • 3. Re: need help making a label
              Marc Autret Level 5

              I'd say:


              var cleanName = myDoc.properties.name.replace(/\.\w+$/,'');




              • 4. Re: need help making a label
                sethkhouri Level 1

                Thank you

                • 5. Re: need help making a label
                  sethkhouri Level 1

                  Hi Marc


                  If i can ask you just one last question,

                  in the label I also want to add the page number to it, This is what i am using.

                  myLabel = myDocument.properties.name.replace(/\D+/,'').split(' ')[0].split('_')[0]+'_' + app.activeWindow.activePage.name+'_'+myCounter;

                  the issue is that when i run this from a multi page doc it adds the same page number on each page,


                  I am assuming because it has something to do with the script looking at all the graphic elements in the entire document instead of perhaps doing a page count, then starting on the first page, then moving onto the second page etc etc.

                  I think it may have something to do with line 2 below, I need to somehow at this point add in a function to count all the pages,

                  then apply the label page by page, not sue how to do that.



                  function myAddLabels(myLabelType, myLabelHeight, myLabelOffset, myStyle, mySwatch){ 
                    var myDocument = app.documents.item(0);
                    myStoriesArray = new Array();
                    if (app.selection.length == 0) // If nothing is selected apply caption to all graphics in the document
                    var myConfirmation = confirm("Add captions to all images in the document?", false, "LabelGraphics.jsx" );
                    if (myConfirmation == true)
                    var myGraphics = myDocument.allGraphics;
                    { // If graphics are selected, just add captions to the selected items, as long as they are rectangles(image frames)
                    var myConfirmation = true;
                    var mySelections = app.selection;
                    myGraphics = new Array();
                    for(i = 0; i < mySelections.length; i++){
                    if(mySelections[i] == "[object Rectangle]"){   //Check to make sure selection only includes rectangles
                    //alert("Objects other than graphics were selected!");
                    //Nothing happens if you don't select at least one graphic