7 Replies Latest reply on Jul 13, 2009 1:46 AM by [Jongware]

    Need a script

    martinn12005 Level 1

      Hi,

       

      I need a script for the following.

       

      I have a magazine that I produce monthly.

      The magazine is made up of boxes where text and pictures are entered.

       

      Like this example PAGE (just setup very quickly and roughly)

      http://www.safedate.net/download/1.jpg

       

       

      I would like Indesign to assign a ID tracking number that I can then use in my customer managing software to track my customers.

      The ID number I would place in a area like this

       

      http://www.safedate.net/download/2.jpg

       

      In order for me to place all the ID numbers quickly into my customer managing software I would like Indesign to also have an option to export the list of al created ID Numbers and which.

       

      In the perfect wolrd, but I guess this is getting complicated, it would be great to the import the numbers into my customer managing software, if a customer gives me a call regarding a advert I simply click the ID number within the software and Indesign will open to show me the advertisement.

       

      But we can´t have it all.

       

      Is this possible?

        • 1. Re: Need a script
          martinn12005 Level 1

          I forgot to say please. It sounds a little rude he he

          • 2. Re: Need a script
            [Jongware] Most Valuable Participant
            I forgot to say please.

             

            Oh okay.

            Do you really need the customer number visible to all? This quicky sets the selected text frame label -- it's there to store "invisible" data. (You can also see and change it, when selected, in the Script Label panel.)

             

            Select a frame and run this script:

             

            if (app.selection[0].constructor.name != "TextFrame")
            {
             alert ("Please select a text frame");
             exit(0);
            }
            theFrame = app.selection[0];
            var myDialog = app.dialogs.add ({name:"Add/Change ID",canCancel:true});
            with (myDialog)
            {
             with (dialogColumns.add())
             {
              with (dialogRows.add())
              {
               staticTexts.add ({staticLabel:"ID"});
               var idField = textEditboxes.add ({editContents:theFrame.label});
              }
             }
            }
            if (myDialog.show() == true)
            {
             theFrame.label = idField.editContents;
            }
            

            Next, if you need to find a frame with a certain customer ID, run this one:

            var myDialog = app.dialogs.add ({name:"Find ID",canCancel:true});
            with (myDialog)
            {
             with (dialogColumns.add())
             {
              with (dialogRows.add())
              {
               staticTexts.add ({staticLabel:"ID"});
               var idField = textEditboxes.add ({editContents:""});
              }
             }
            }
            if (myDialog.show() == true)
            {
             for (var i=0; i<app.activeDocument.textFrames.length; i++)
             {
              checkFrame (app.activeDocument.textFrames[i]);
             }
             alert ('No ID matching "'+idField.editContents+'" found!');
            }
            function checkFrame (theFrame)
            {
             if (theFrame.label == idField.editContents)
             {
              p = getPage (theFrame);
              app.activeWindow.activePage = p;
              theFrame.select();
              exit(0);
             }
             for (var i=0; i<theFrame.textFrames.length; i++)
             {
              checkFrame (theFrame.textFrames[i]);
             }
            }
            // (Courtesy of Dave Saunders)
            function getPage(theObj)
            {
             if (theObj.constructor.name == "Page") return theObj;
             if (theObj.constructor.name == "Character")
              return getPage(theObj.parentTextFrames[0]);
             if (theObj.constructor.name == "Application")
             {
              // Frame is on an unexpected place...
              alert ("Where am I? Giving up...");
              exit(0);
             }
             return getPage(theObj.parent)
            }
            

            Warning: fairly untested, may contain bugs ... (especially if you are partial to inserting text frames inside text frames ad nauseum).

             

            As for gathering the numbers used, I'd need an output format (plain text?). I don't know how to connect to a database, but perhaps one of the VB scripters can concoct somethingconnecting to Access or Excel.

            • 3. Re: Need a script
              [Jongware] Most Valuable Participant

              ... and here is a variant of the second script; this one presents you with a user friendly drop down list containing all frame labels.

               

              var allLabels = new Array;
              var allTheirFrames = new Array;
              for (var i=0; i<app.activeDocument.textFrames.length; i++)
               checkFrame (app.activeDocument.textFrames[i]);
              var myDialog = app.dialogs.add ({name:"Find ID",canCancel:true});
              with (myDialog)
              {
               with (dialogColumns.add())
               {
                with (dialogRows.add())
                {
                 staticTexts.add ({staticLabel:"ID"});
                 dropDown = dropdowns.add ({stringList:allLabels, selectedIndex:0});
                }
               }
              }
              if (myDialog.show() == true)
              {
               p = getPage (allTheirFrames[dropDown.selectedIndex]);
               app.activeWindow.activePage = p;
               allTheirFrames[dropDown.selectedIndex].select();
               exit(0);
              }
              function checkFrame (theFrame)
              {
               if (theFrame.label != "")
               {
                allLabels.push (theFrame.label);
                allTheirFrames.push (theFrame);
               }
               for (var i=0; i<theFrame.textFrames.length; i++)
               {
                checkFrame (theFrame.textFrames[i]);
               }
              }
              // (Courtesy of Dave Saunders)
              function getPage(theObj)
              {
               if (theObj.constructor.name == "Page") return theObj;
               if (theObj.constructor.name == "Character")
                return getPage(theObj.parentTextFrames[0]);   // CHANGED
               if (theObj.constructor.name == "Application")
               {
                // Frame is on an unexpected place...
                alert ("Where am I? Giving up...");
                exit(0);
               }
               return getPage(theObj.parent)
              }
              

              Perhaps I can create something with ScriptUI -- that would allow you to set, change, and (if possible) export data from within one dialog. No promises, tho'.

               

              (Can anyone tell me how to sort the labels along with the parent frame array? They appear in a somewhat haphazard order now...)

               

              [Edit] oops -- this was for CS4. Changed the line marked by "CHANGED".

              • 4. Re: Need a script
                martinn12005 Level 1

                Hi,

                 

                I run the script fine. I would prefer a visible id number preferably because the public will also have to quote me this number when they have any queries.

                 

                When I run the script I have  box titled "Find ID". The scroll down box is empty, How do I assign ID numbers to it?

                (i´ve just edited this. It appears I missed something, I will go and try it again).

                 

                Thank you.

                • 5. Re: Need a script
                  martinn12005 Level 1

                  I am looking for software to manage my customer effectively but I am having a hard time to find one. I am hoping I can find a pakcage that can generate the ID number, if not hoepfully this script can generate the numbers require and then I can import them into the customer management software.

                  • 6. Re: Need a script
                    martinn12005 Level 1

                    I have noticed a bug with this script.

                     

                    I create a text box and enter a ID number 123456.

                    I then alt select and drag to duplicate the text box with the number 123456 still inside the text box. I then replace the numbers on all duplicated frames, run the script find ID and only find multiple listings of the ID number 123456 listed within the scroll down box.

                    This error still remains even if I duplicated the frame with no ID number inside. The error also remains when creating a new frame with a new ID number. It still only displays 123456 (the original ID number created in the first frame).

                    • 7. Re: Need a script
                      [Jongware] Most Valuable Participant

                      Using an InDesign script to generate customer id's would be a bad idea. The only way (I see) to do so would be using the random number generator. That's possible, but to be sure it's unique, you'd need to know all other assigned numbers -- including those in all the other catalogs you created with this system, and that means you'd have to have these documents opened in InDesign -- all of them, every time you need a number.

                      Using an external application to create and manage the customer id's is the way to go.

                       

                      As for the placement of the id in your document: since it's plain visible text, by far the easiest way to locate them is to create a unique paragraph or character style for the id's. All you have to do is remember to assign this style to the id as soon as you add one into the text (and, incidentally, use the style exclusively for id numbers). InDesign can search for text with a specified paragraph or character style assigned.