2 Replies Latest reply on Apr 19, 2016 11:35 PM by SubbaiyaArasu

    Script to place graphics according to embedded filenames

    Kenneth C. Benson Level 4

      Is there a script out there that will go through my Indesign CS6 file, find filenames in double angle brackets (like <<eq0042.eps>>) and replace each one with the appropriate linked graphic already resident in a links folder? I'm working on a math book using Mathtype. Mathtype will batch export equations to eps files from Word, leaving a filename marker in place of each equation. This book has thousands of equations, so I'm looking for a way to speed up the process of placing them.


      Bonus: how about a script that will measure the height of all graphic frames and apply object styles appropriate to their height? For example, if the frame was 29 pts high, the script would apply style1. If the frame was 30 pts high, the script would apply style2, etc. There would be, maybe, two dozen heights (all whole numbers in points) with two dozen corresponding object styles. Any other graphic frames would be ignored. The purpose of the style is to shift the frame below the baseline an appropriate amount for the equation. For a 29 pt stacked fraction, I need to offset the frame -11 pts. This would be easy if Find/Replace format included height.


      The reason I'm not simply bringing equations in directly from Word (for anyone who knows Mathtype) is because equations come in as wmf (cleverly disguised as eps, but wmf nonetheless), and wmf is giving me problems with occasional, random, nondisplay of equation elements. I've asked Design Science about it, but I'm not holding my breath.


      My efforts at writing scripts from scratch have been abysmal, but I'm pretty good at altering existing scripts. If you've got something that's close, I can probably adapt it to what I'm doing.

        • 1. Re: Script to place graphics according to embedded filenames
          G. Singelmann Level 3
          #target indesign
          function main() {
            var the_doc = app.activeDocument;
            var the_doc_path = the_doc.filePath.fullName;
            var the_story = app.selection[0].parentStory;
            app.findGrepPreferences = null;
            app.findGrepPreferences.findWhat = "<[^>]+>";
            var findings = the_story.findGrep(true);
            var the_content = "";
            var the_filename = "";
            var the_text;
            for (var n = 0; n < findings.length;  n++) {
            the_text = findings[n];
            the_content = the_text.contents;
            the_filename = the_doc_path + "/mv/" + the_content.substr( 1, the_content.length -2);
            var aLink = the_text.place(File(the_filename));


          I wrote this a long time ago. It should give you something to start from.




          • 2. Re: Script to place graphics according to embedded filenames
            SubbaiyaArasu Level 1



            The below code will help to insert art files. if you need more reference check this link Re: figure placing in cs2/cs3



            var myFolder=Folder.selectDialog("Choose a Art folder!"); 
            app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing; 
            mySearch = app.findGrep(true); 
                    var imgLoc=mySearch[a].contents;
                    imgLoc=imgLoc.replace("<<", "");
                    imgLoc=imgLoc.replace(">>", "");
                    //alert(myFolder + "/" + imgLoc);
                    mySearch[a].characters[0].insertionPoints[0].place(File(myFolder + "/" + imgLoc)); 
                      }catch(e)    {} 
            app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing; 
            app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
            alert("process Completed");