12 Replies Latest reply on Aug 31, 2010 4:48 AM by [Jongware]

    Place inline graphics

    Frillo@Adobe Level 1

      Hello everybody, I'm trying to find a way to accomplish this: I've got hundreds of tables of volleyball fixtures to set up VERY quickly, and in one column of these I have the 3 letter defining the countries (i.e. USA for United States, RSA for South Africa, VEN for Venezuela and so on). What I need is a script that reads the column, search for the eps with the same name in a specified folder (USA.eps, RSA.eps, VEN.eps) and places it after the country id's as an inline graphics. Is this very difficult to accomplish? I can script a bit (applescript, actually), but IThink this would need a Pro approach… If someone could just give me a start I would be very very grateful. Thank you, F

        • 1. Re: Place inline graphics
          Harbs. Level 6

          1) Identify the folder and files using the File and Folder objects.

          2) Do a grep search for \u\u\u (in a script that would be: "\\u\\u\\u")

          3) Loop through the results (it's an array) and use finds[i].insertionPoints[-1].place(myGraphicFile);

           

          You might want to get hold of a reference to the placed file, and apply an object style...

           

          Harbs

          1 person found this helpful
          • 2. Re: Place inline graphics
            [Jongware] Most Valuable Participant

            No problem. Actually this is Javascript, but that's how I roll. Adjust the path in the first line, select the column of your table containing just those 3-letter abbrevs (this should be all there is in those cells, right?), run the script, enjoy.

             

            imagePath = "~/Documents";
            if (app.selection.length == 1 && (app.selection[0] instanceof Column || app.selection[0] instanceof Cell))
            {
                 app.findGrepPreferences = null;
                 app.findGrepPreferences.findWhat = "^\\u+$";
                 list = app.selection[0].findGrep(true);
                 err = [];
                 for (i=0; i<list.length; i++)
                 {
                      try {
                           list[i].insertionPoints[-1].place (File(imagePath+"/"+list[i].contents+".jpg"));
                      } catch(_)
                      {
                           err.push ('No image found for "'+list[i].contents+'"');
                      }
                 }
                 if (err.length)
                      alert (err.join("\r"));
            }
            

            • 3. Re: Place inline graphics
              [Jongware] Most Valuable Participant

              Actually Harbs makes a good point. It's possible to apply an Object style right after placing, so if you want to do anything else after placing the images (a border, or a drop shadow, or some custom text wrap), the script can apply one for you.

              • 4. Re: Place inline graphics
                Frillo@Adobe Level 1

                You are an absolute star!

                It worked like a charm, just after I entered the correct path for the images folder (and adjusting the extension from .jpg to .eps).

                I'm afraid I can't understand JS at all, feel much more confortable with Applescript, but I didn't know how to implement all this.

                Thank you again, saved me lots of work...

                g

                • 5. Re: Place inline graphics
                  [Jongware] Most Valuable Participant

                  Oh, good catch! I used jpegs because that's what I had on my harddisk ... Fortunately, you're not easily scared away

                   

                  I can't work with AppleScript. For short command sequences it seems like a programmer's dream come through: a perfectly readable syntax with clear instructions. However, the Indesign interface is so complicated you end up with a long list of "of"s and "in"s when all you want to do is to refer to the x-th occurrence of a word in an y-th text frame on the z-th page of your current active document -- that's something like "app.activeDocument.pages[z].textFrames[y].words[x]" in Javascript. IOW, much more agreeable my the inner geek.

                  • 6. Re: Place inline graphics
                    Frillo@Adobe Level 1

                    Ok, now I have another problem...

                    Did I say "inline"? I intended "anchored", actually...

                    The script works perfectly but it places the images as inline graphics; I tried to perform a find/change on inline placed graphics but it doesn't seem to work, it just doesn't find not even one of them.

                     

                    My modified script is this:

                     

                    //DESCRIPTION: Place flags

                    imagePath = "~/Desktop/YearBook2008/Flags";

                    if (app.selection.length == 1 && (app.selection[0] instanceof Column || app.selection[0] instanceof Cell))

                    {

                         app.findGrepPreferences = null;

                         app.findGrepPreferences.findWhat = "^\\u{3}$";

                         list = app.selection[0].findGrep(true);

                         err = [];

                         for (i=0; i<list.length; i++)

                         {

                              try {

                                   list[i].insertionPoints[-1].place (File(imagePath+"/"+list[i].contents+".eps"));

                              } catch(_)

                              {

                                   err.push ('No image found for "'+list[i].contents+'"');

                              }

                         }

                         if (err.length)

                              alert (err.join("\r"));

                    }

                     

                     

                    Can I apply an object style to the "to be placed" images? Or, even better, how can I Find/Change them after the insertion?

                    thx,

                    f

                     

                    Where can I find more on Javascript and InDesign?

                    Thx again,

                    f

                    • 7. Re: Place inline graphics
                      [Jongware] Most Valuable Participant

                      The command 'place' returns an array of the objects it placed -- usually, for a single image, it's a one-item array (still an array, though).

                       

                      Try this:

                       

                      img = list[i].insertionPoints[-1].place (File(imagePath+"/"+list[i].contents+".eps"));

                      img[0].appliedObjectStyle = app.activeDocument.objectStyles.item("YourObjectStyleName");

                       

                      Where can I find more on Javascript and InDesign?

                       

                      "More", as in, you've read all of Adobe's Introduction To, Tutorial For, and In-Depth Guide to Scripting? (In case you didn't: they can be found here, under the button "Scripting Resources").

                      I found I could learn a lot from general Javascript programmers -- you just have to learn to ignore the HTML-lingo that usually accompanies it. A lot of advanced stuff can be found by just googling for what you need.

                       

                      The Definitive Reference is the one built-in into the ESTK (under the Help menu), but a lot of folks were very happy to find my version of the exact same information (here) because my CHM format is much more pleasing to the eye, has loads more internal hyperlinks, displays object hierarchies, and, with a good viewer, supports both a good index and free-text searching. That's why, for example, for another q on this forum I could search for "preview" and see at a glance all objects, methods, and properties that start with this string, finding nothing mentions 'fonts'.

                       

                      There are several web sites devoted to scripting InDesign only. A few of them (and running the risk of missing the best) are http://indiscripts.com/, http://indisnip.wordpress.com/, http://jsid.blogspot.com/ (some oldies -- but still good. Dave Where Are You?), and fellow scripter Peter Kahrel wrote several books on InDesign -- this one specifically for scripters (or perhaps there is a newer version, this was the first goog hit).

                       

                      By the way: the best information on the interweb can be found here. That's this forum, of course.

                      • 8. Re: Place inline graphics
                        Frillo@Adobe Level 1

                        [Jongware] wrote:

                         

                        Try this:

                         

                        img = list[i].insertionPoints[-1].place (File(imagePath+"/"+list[i].contents+".eps"));

                        img[0].appliedObjectStyle = app.activeDocument.objectStyles.item("YourObjectStyleName");

                         

                        Nop, bad luck this time...

                        It doesn't seem to work, it just doesn't apply any object style.

                         

                        What does the "img[0]" in the second line above mean? Is it a sort of incremental flag or what?

                        Thx for your time,

                        f

                        • 9. Re: Place inline graphics
                          [Jongware] Most Valuable Participant

                          Okay, that took some time (too long! -- I knew this!).

                          You cannot apply an object style to an image, and that's what is returned. You have to apply it to the image's parent instead, like this:

                           

                          img[0].parent.appliedObjectStyle = app.activeDocument.objectStyles.item("YourObjectStyleName");

                           

                          ("Nothing happened" because this command was also inside the try..catch error handler.

                          I presume you changed "YourObjectStyleName" to the actual Object Style name you are using, though.)

                           

                          The [0] notation is standard Javascript syntax to access an array. The 'place' command returns an array of all images it placed, so to refer to the first (and usually, the only) item you need img[0], rather than plain 'img'.

                          • 10. Re: Place inline graphics
                            Frillo@Adobe Level 1

                            Sorry I'm late to THANK YOU again for your effort, now it works really perfectly.

                            God knows why you should address the image's parent instead of the image itself but, hey, who cares...

                            No, just kidding, I'm definitely willing to understand a bit more and I'm looking for a good book, or video, or whatever could teach me the basics.

                            Thank you again, hope I'll be able some day to help someone else like you did with me

                            f

                            • 11. Re: Place inline graphics
                              Frillo@Adobe Level 1

                              Ooooh, now I have it!

                              Maybe it's because you're applying the object style to the CONTAINER of the object (the graphic frame), not to the actual object, is it like this?

                              f

                              • 12. Re: Place inline graphics
                                [Jongware] Most Valuable Participant

                                yep

                                 

                                It's possible to place an AI or PDF with a transparent background; then you can apply, for example, a Drop Shadow to either the 'contents' of the image, meaning the non-transparent bits, or to the frame that contains the image.

                                1 person found this helpful