Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Script for identifying undersized graphics frames?

Return to Member Forum

  • Author
    Posts
    • #55732
      kdennison
      Member

      Hi All,

      I'm hoping someone on here might be able to help with a scripting challenge. My company is working on a large chemistry textbook with thousands of chemistry structures that are placed vector graphics. One issue we've had in the past is that sometimes a graphics frame is inadvertently adjusted so part of the graphic is cropped out, or a graphic is modified in a way that makes it a bit larger. With so many graphics it becomes quite a chore to check every graphic visually. Our dream is a script that would provide for graphics the equivalent of the overset text warning, by flagging any graphics frames in a document with dimensions smaller than those of the placed graphics within them. We would not want the frames to be automatically resized, because some graphics DO need to be cropped out; flagging the undersized frames would allow the operator to adjust only those that need it.

      We're working in ID CS4 on Mac, and the graphics are a mix of Illustrator CS2 and CS4 eps files.

      Any suggestions will be greatly appreciated!

    • #55736

      I agree it cannot be scripted to automatically adjust bounding boxes. A script doesn't have access to the 'contents' of a placed image, thus it cannot check if it's just whitespace that got cropped, or an incredibly important atom just got deleted.

      A script can be aware of an image being cropped, but (fortunately!) you thought of mentioning that might also be valid. So you are correct: only all cropped images can be flagged, and it's up to the operator to decide whether it's wrong or not.

      Hold on while I do some testing. (Insert telephone waiting muzak here.)

      (di da di da … got something … almost done …)

      Okay — finding suspicious items is not the problem. How they should be marked, however, is. This javascript creates a bright red “Warning” color and a “Warning” object style with a thick fat red line, and applies it to the frame. So — do not use this if you are already using another object style on your images! (In that case I'd like to hear from you what other options there are to mark items…)

      try { app.activeDocument.objectStyles.add({name:”warning”}); } catch(_) {}

      try { app.activeDocument.colors.add ({space:ColorSpace.RGB, colorValue:[255,0,0], name:”Warning”}); } catch (_) {}

      warningStyle = app.activeDocument.objectStyles.item(“warning”);

      warningStyle.properties = { enableStroke:true, enableFill:false, strokeColor:app.activeDocument.swatches.item(“Warning”), strokeWeight:5, strokeAlignment:StrokeAlignment.INSIDE_ALIGNMENT};

      imageList = app.activeDocument.allGraphics;

      found = 0;

      for (im=0; im<imageList.length; im++)

      {

      try { if (isImageCropped (imageList[im].geometricBounds, imageList[im].parent.geometricBounds))

      { found++; imageList[im].parent.appliedObjectStyle = warningStyle; } } catch (_) { found++; imageList[im].parent.appliedObjectStyle = warningStyle; }

      }

      alert (“Found “+(found?found:”no”)+” suspicious frame”+(found==1?””:”s”));

      function isImageCropped (img, frame) {

      if (img[0] < frame[0] || img[1] < frame[1] || img[2] > frame[2] || img[3] > frame[3]) return true; return false; }

    • #55737
      kdennison
      Member

      oooh, this looks promising–thanks so much for the speedy response! I don't think we're styling the graphics frames for this title, at least, so it should work for the immediate need. We'll try this out first thing in the morning, and I'll let you know how it works.

    • #55738

      If you can think of another way to identify potentially bad images, call me in the morning. I actually was thinking of adding a drop shadow :-) (I couldn't figger out how to add it to a style with a script.)

      There are not that very much options, other than adding some effect. Perhaps a dialog that let's you browse through the “suspicious” list?

    • #55745
      kdennison
      Member

      OK, we have tested the script, and it does EXACTLY what we needed it to–you are awesome! You even knew to set the red stroke on the inside of the frame so there was no reflow of text with anchored frames. Thanks a million for your help.

Viewing 4 reply threads
  • You must be logged in to reply to this topic.
Forum Ads