• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Script to place graphics according to embedded filenames

Advisor ,
Apr 19, 2016 Apr 19, 2016

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

339

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 19, 2016 Apr 19, 2016

Copy link to clipboard

Copied

#target indesign

main();

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;

  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.

HTH

Gerald

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 19, 2016 Apr 19, 2016

Copy link to clipboard

Copied

LATEST

Hi,

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!");

//alert(myFolder);

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

app.findGrepPreferences.findWhat="<<[^>]+>>";

mySearch = app.findGrep(true);

for(a=0;a<mySearch.length;a++){

    try{

        var imgLoc=mySearch.contents;

        imgLoc=imgLoc.replace("<<", "");

        imgLoc=imgLoc.replace(">>", "");

        //alert(myFolder + "/" + imgLoc);

        mySearch.characters[0].insertionPoints[0].place(File(myFolder + "/" + imgLoc));

          }catch(e)    {}

    }

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

app.findGrepPreferences.findWhat="<<[^>]+>>";

app.changeGrepPreferences.changeTo="";

app.documents.item(0).changeGrep();

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

alert("process Completed");

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines