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

Simple InDesign AppleScript – Need Help

Explorer ,
Jul 23, 2019 Jul 23, 2019

Please help! I'm new to AppleScript and I'm looking for a way to find and delete empty graphics frames in InDesign based on its size only. For example... find and delete every empty graphics frame in a 100-page document that is 4" W x 2" H. I'm data merging a document that is creating some empty frames that are all the same size, but I don't want to delete every empty frame. I need those frames for something else.

TOPICS
Scripting
1.3K
Translate
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

correct answers 1 Correct answer

Enthusiast , Jul 23, 2019 Jul 23, 2019

Hi,

You could try a script similar to the following:

set theCount to 0

set maxWid to 4

set maxHgt to 2

tell application "Adobe InDesign CC 2019"

  set measurement unit of script preferences to inches

  tell document 1

  set foundSet to rectangles

  repeat with eachItem in foundSet

  if (count of page items of eachItem) = 0 then

  copy geometric bounds of eachItem to {y0, x0, y1, x1}

  set theWid to x1 - x0

  set theHgt to y1 - y1

  if theWidmaxWid and theHgtmaxHgt then

  delete eachItem

  set theCount to

...
Translate
Enthusiast ,
Jul 23, 2019 Jul 23, 2019

Hi,

You could try a script similar to the following:

set theCount to 0

set maxWid to 4

set maxHgt to 2

tell application "Adobe InDesign CC 2019"

  set measurement unit of script preferences to inches

  tell document 1

  set foundSet to rectangles

  repeat with eachItem in foundSet

  if (count of page items of eachItem) = 0 then

  copy geometric bounds of eachItem to {y0, x0, y1, x1}

  set theWid to x1 - x0

  set theHgt to y1 - y1

  if theWidmaxWid and theHgtmaxHgt then

  delete eachItem

  set theCount to theCount + 1

  end if

  end if

  end repeat

  end tell

end tell

activate

display alert ("Rectangles deleted " & theCount)

This script will delete all rectangles in the document that contain no page items (images, etc.) and are smaller than or equal to 4" by 2".

Make sure you save your document before running the script so you can revert to the original if it does not work as anticipated.

Hope this helps.

Translate
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
Explorer ,
Jul 24, 2019 Jul 24, 2019

Thank you so much for helping! The script works great and I appreciate the quick reply!

Question though, if I want the script to only find and delete the 4" x 2" squares (nothing smaller) I would think this would work:

if theWid = maxWid and theHgt = maxHgt then

  delete eachItem

However, being an Applescript beginner, that doesn't work. Any suggestions? I'm trying to learn as much as possible about this.

Translate
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
Enthusiast ,
Jul 24, 2019 Jul 24, 2019

Hi,

If you are sure that all of the items you want to delete are exactly 4 in x 2 in then change the lesser than or equal to signs to equal signs in the script.

if theWid = maxWid and theHgt = maxHgt then

In my experience, subtle differences in size (round off errors, etc.) can make checking for equal sizes problematic. For this reason I look for a range of sizes as in less than or equal to.

if theWid < 4.1 and theWid > 3.9 and theHgt < 2.1 and theHgt > 1.9 then

If using equals works--then go for it!

It's better if there is some other way that you can define an object: a label or a name is preferred. Assigning a label or a name to an object is often done as part of its being created. Just some ideas for you as a beginner.

Good luck!

Translate
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
Explorer ,
Jul 24, 2019 Jul 24, 2019
LATEST

Thanks for your help! I really appreciate it!

Translate
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