7 Replies Latest reply on Oct 6, 2011 6:37 AM by MarkG99

    Please advise -Newbie iD scripting question

    MarkG99

      Hi

      I have only just begun learning scripting of InDesign - (about 2 days ago actually). AppleScript and JavaScript.

      There is something I need to create immediately (or very soon). It seems pretty simple, but I'm not sure.

      My question is this - Is this something which requires a simple script I could create today?

      Or is it something which will require much more study?

       

      Basically - If I MUST get this done ASAP should I be using my time trying to create a script or is it better for me to just do this manually (drudgery, but do-able) and leave the scripting learning for another time.

       

      This is what I want to accomplish -

      I have a page with only one element which is not a master page item (in my case a text frame containing the magazine title)

       

      I want to be able to quickly see this page in many versions where the only difference is the font of the title.

       

      Example:

      I have this page with only one item and I have a list of 20 typefaces I want to try. I want InDesign to make my single page document into a 20 page document where all the pages are identical - EXCEPT for the typeface used for the title.

       

      This is the same as using a type manger where you create a set of fonts; type in some text and see it displayed in the each font in your set. What I want is to see a preview of each typeface BUT already in MY layout with all of the other elements of MY page. Then I can quickly select which typeface works the best.

       

      I'd be grateful for any opinion from any more experienced scripters.

       

      Thank You ahead of time

      -Mark

        • 1. Re: Please advise -Newbie iD scripting question
          Manan Joshi Level 4

          Hi Mark,

           

          My advise to you would be to get down and try writing the script you want to create. Javascript is not that daunting to learn to start scripting unless you get into something complex. So if you have a general idea of the Indesign object model its best you start writing code.

           

          And in the process try understanding the object model of Indesign, that will be required to enhance your skills and write complex scripts

           

          In my opinion one learns best by writing code, so happy scripting.

           

          Hope this helps you and get's you started.

           

          Manan Joshi

           

          - Efficient InDesign Solutions -

          MetaDesign Solutions

          http://metadesignsolutions.com/services/indesign-development.php

          • 2. Re: Please advise -Newbie iD scripting question
            absqua Level 4

            Here's a little something to get you started:

             

            if(app.documents.length === 0){
                exit();
            }
            var doc = app.activeDocument;
            var page = doc.pages[0];
            var newPage, i;
            page.textFrames.itemByName("title box").texts[0].appliedFont = app.fonts[0];
            for (i = 1;i<app.fonts.length;i++){
                newPage = page.duplicate(LocationOptions.AT_END);
                newPage.textFrames.itemByName("title box").texts[0].appliedFont = app.fonts[i];
            }
            

             

            A couple of notes: For this to work, you will need to have renamed the text frame you want to change "title box" in the layers palette. You said that your page only has one element, but doing it this way you can have other things as well and the script will still be able to find the right box to modify. Also, the script will make a new page for every font InDesign has loaded; if you want to use a subset of those fonts, you'll have to probably create an array of font names you want to apply, and the script will need some modification. Note also that applying different fonts may cause your title to overflow, and the script might need to be considerably more sophisticated to handle that scenario.

             

            Jeff

            1 person found this helpful
            • 3. Re: Please advise -Newbie iD scripting question
              MarkG99 Level 1

              Hi Jeff,

               

              WOW! thank you so much!

               

              You just answered a big question I was stuck on in my baby steps of learning. Everywhere I see in instructions "name the text frame (or any item)..."

              I could NOT figure out how to name one particular item. It's probably SO VERY basic that it's not explained anywhere I could find. So you don't actually name the ITEM but name a LAYER with only that item on it? Is that correct?

               

              As for fitting the text - that's not a problem since I make it tiny in its frame and then run this script I downloaded:

              http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&extid=1046587

              Which works fine.

               

              I do want to create an array list of particular fonts since all the fonts loaded into inDesign include system fonts and other fonts I'm not interested in at the moment; so I'd like it to create only the pages I want, instead of creating x number of pages which then I'll have to go through page by page to weed out the pages I don't need.

               

              One other question I have is - what version of the font name do I use in the array list?

              A font could have different names for the same thing like; font name in the menu, its postscript font name, the name of the actual font file sitting on your hard drive etc...

               

              And when I create the array I'll use 

              var name++

              so that the newly created page will use the next font in the array list - is that correct?

               

               

              Thank you SO VERY MUCH for your help!!

              Since I remember the world before the internet my mind is boggled and amazed if I try to imagine how much effort this learning process would require not so long ago-

              • maybe go to library
              • maybe go to bookstore
              • buy book
              • search in book
              • learn from book
              • what if I have a question for the author?
              • maybe I'll take a scripting course

              it could have gone on and on and on for weeks or months before I found the answer I was looking for.

               

              It's generous people (like you) who make the internet miraculous!

               

              Thank You

              -Mark

              • 4. Re: Please advise -Newbie iD scripting question
                absqua Level 4

                I'm glad to be of help Mark. I shudder to think how many hours I would have wasted if not for the generous help of participants on this forum.

                 

                As far as naming page items: this changed in CS5. I assumed you were using CS5, though I now see there is nothing in your post to support that assumption. In CS4 and before, page items were named via their script label; in CS5 and beyond, they are named in the layers palette. So, where you name the item (to later be retrieved by, e.g., page.itemByName()) depends on the version you're scripting. To apply a script label, open Window=>Automation=>Script Label, select the item, and name it in the Script Label palette.

                 

                The best way to get the font names to loop through is probably via script. I would get a master list of all fonts loaded, and then edit that down or pick items out of it. You can generate the code for an array this way:

                 

                var fontNameArray = [],
                    i;
                for (i = 0;i<app.fonts.length;i++){
                    fontNameArray[fontNameArray.length] = app.fonts[i].name;
                }
                $.writeln("[\"" + fontNameArray.join("\", \"") + "\"]");
                

                 

                This will write the code for such an array to the console in the ESTK.

                 

                Once you have a smaller array of font names you want, this modification to the original script should get you there:

                 

                if(app.documents.length === 0){
                    exit();
                }
                var doc = app.activeDocument;
                var page = doc.pages[0];
                var fontNames = ["Alright Sans    Thin", "Alright Sans    Light", "Alright Sans    Light Italic", "Alright Sans    Regular"];
                var newPage, i;
                page.textFrames.itemByName("title box").texts[0].appliedFont = app.fonts.itemByName(fontNames[0]);
                for (i = 1;i<fontNames.length;i++){
                    newPage = page.duplicate(LocationOptions.AT_END);
                    newPage.textFrames.itemByName("title box").texts[0].appliedFont = app.fonts.itemByName(fontNames[i]);
                }
                

                 

                I'm doing something a little goofy with iterating through the font name array that I should explain. Normally a for loop will start with your iterator (variable "i" here) at zero. I applied the first font (fontNames[0]) before entering the loop and then started at 1, with the second item in the array. If I had not done this, your first page would have been your "base" page, with whatever font you had applied manually, and your document would have had one extra page; as written, your first page will use the first font in your array and your "base" page will be effectively gone.

                 

                The quickest way to get up to speed scripting InDesign is with Peter Kahrel's excellent book. That's how I started. (And I would focus on JavaScript—because it's cross-platform and because there are so many resources for learning and using it—unless you have an overwhelming reason to use Applescript instead.)

                1 person found this helpful
                • 5. Re: Please advise -Newbie iD scripting question
                  MarkG99 Level 1

                  Hi Jeff,

                  I am using CS5.

                  Thanks again. Your answers are a big help.

                  I didn't know about the script label panel because I've just gotten through "Adobe Introduction to Scripting" where it isn't mentioned.

                  But now I see the info about it in the much longer "InDesignCS5_ScriptingGuide_JS" which I haven't gone through yet.

                  Your "font name listing" script worked perfectly. I now can see the way inDesign names the fonts internally.

                  So far I've only been trying your first script before I do an array.

                  I named my text frame title box in the "Script Label" panel but the script fails and gives me an "object is invalid" error when it reaches this line -

                  page.textFrames.itemByName("title box").texts[0].appliedFont = app.fonts[0];

                  when I delete that line and also delete

                  newPage.textFrames.itemByName("title box").texts[0].appliedFont = app.fonts[i];

                   

                  it duplicates my page as many times as there are fonts loaded, but the fonts are the same on every page.

                  So it seems that it is correctly counting the number of fonts loaded and duplicating the page accordingly,

                  but something is wrong with the command which is pointing to the text frame.

                   

                  I've been trying different things, but I can't figure out what the problem is.

                   

                  I don't have time to do more tonight, but I'll keep going tomorrow evening.

                   

                  Thanks again for the book recommendation and all your help.

                  -Mark

                  • 6. Re: Please advise -Newbie iD scripting question
                    absqua Level 4

                    It was in CS4 and before that you used script labels to name page items. In CS5, you name them in the layers palette, like this:

                     

                    Picture 2.PNG

                    • 7. Re: Please advise -Newbie iD scripting question
                      MarkG99 Level 1

                      Jeff,

                      Once again - Thank You So Much!!

                       

                      Slowly, Slowly, I'm learning.

                      Your examples have helped tremendously.

                      Seeing the script operating line-by-line, working on MY particular problem instead of some imaginary example from a textbook REALLY REALLY helps.

                       

                      At this stage of my (or anyone's) learning I'm overwhelmed with info from different books, instructions, guides etc.. - that I missed a small detail like - how to name an item in CS4 vs CS5. Before that  I only had a couple of hours of frustration trying to figure out where the problem was and your previous post saved me from DAYS of frustration.

                       

                      Thank You!

                      -Mark