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 to change depth of Anchored Objects of a certain depth?

Return to Member Forum

  • Author
    Posts
    • #64390

      Hi,

      I have no scripting experience at all and I'm hoping somebody will be able to help me. I have several customer supplied IDCS5 docs, all with many pages. Each of these docs have hundreds of Anchored Objects that have no Object style applied. But they all have the same depth. I need to change the depth of all them to something different than what they are now.

      Right now they are 25.337 pts deep and I need them to be 30.24 pts deep.

      I've done a quick search of the web and I'm not finding anything that will help me. We are swamped and I don't have time to search anymore, so I'm praying there is somebody out there that can help me with a script or something.

      Thanks so much,

      Janine

    • #64392

      Try this Javascript (on a copy!). First make sure your measurement units are in points! Or else it will try to work in centimeters or inches, or what-have-you-got, and it may even do something — but not what you wanted it to.

      It first gathers all 'pageItems' that are 'inside stories', which is what an anchored object actually is. Then it calls a small helper function that determines if the height (as given by geometricBounds) is in the neighborhood of your 25.337 pts. It needs a bit of a fuzzy comparison, because InDesign doesn't really show all fourteen decimals it internally uses — your anchored object may in fact be 25.336999999 pts high, and comparing it against exactly 25.337 would return “false”!

      Then, if a match is found, it uses the 'add to' subfunction of the 'resize' method to add 4.903 pts.

      allAnchObjects = app.activeDocument.stories.everyItem().pageItems.everyItem().getElements();
      for (i=0; i<allAnchObjects.length; i++)
      {
      if (isRightHeight (allAnchObjects[i]))
      {
      allAnchObjects[i].resize (
      BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS,
      AnchorPoint.TOP_LEFT_ANCHOR,
      ResizeMethods.ADDING_CURRENT_DIMENSIONS_TO,
      [ 0, 4.903 ]);
      }
      }

      function isRightHeight (object)
      {
      var h = object.geometricBounds[2]-object.geometricBounds[0];
      if (h > 25.336 && h < 25.338)
      return true;
      return false;
      }

    • #64404

      Thanks for coming up with this script! You're a lifesaver!!!

      After running the script, it gives me an error on line 15

      Error Number: 30614

      Error String: Invalid object for this request>

      <Source: var h = object.geometricBounds[2]-object.geometricBounds[0];

      but it still changes all of the depths.

      Thanks again,

      Janine

    • #64405

      Hmm, ha-hum. Hmmmm . . . :)

      Okay — I think I know what causes this error. Do you have some overset text, and does it contain an anchored frame as well? In that case the frame is not visible, so there are no 'bounds' to be measured. And you'd never notice it because you can't see that frame.

    • #64406

      Yep, you're right. There was some overset text that contained some of these frames. All fixed now.

      Again, thank-you so much for writing this. You saved me hours of work! Now on to the next crisis!

      Janine

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