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

Applescript to return size of all text frames and image frames

New Here ,
Jul 02, 2019 Jul 02, 2019

I'm new to AppleScript and am wondering if there is a way to return the size of all text frames and all image frames in my active document. Essentially, I am trying to calculate the square inches of all text frames and all image frames so that I can compare the two and find the ratio of text to images in the whole book.

I've been able to use geometric bounds to return the bounds of individual text frames, but I can't figure out how to return the bounds of all text frames in the document and all image frames in the document to compare them.

Sorry that this is a very basic question, most of what I've been able to find so far is about changing frame sizes, not finding the area of frames.

TOPICS
Scripting
1.5K
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

Advocate , Jul 03, 2019 Jul 03, 2019

Hi jalbert_ecwpress ,

I am not that good at applescript, but this might be solution for you.

set list_Of_Text_Frame_Area to {}

tell application id "com.adobe.indesign"

  tell active document

  set every_t to every text frame

  set total_W_x_H to 0

  repeat with this_TextFrame in every_t

  set geo_bounds to 0

  set this_W to 0

  set this_H to 0

  set this_W_x_H to 0

  set geo_bounds to geometric bounds of this_TextFrame

  set this_H to ((item 3 of geo_bounds) - (item 1 of geo_bounds))

  set this_W to ((item 4

...
Translate
Advocate ,
Jul 02, 2019 Jul 02, 2019

Hi Jalbert,

Logic of getting area of allImages & textframe is very simple.

You are getting all text frame at that time push that frame/images area by calculating it in a global array.

Your array could be multi dimentional as per your need.

And at the end just return it.

Best

Sunil

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
Participant ,
Jul 03, 2019 Jul 03, 2019

-- Here's one way to get the total area of all text frames. It could be used as the basis for getting the area of all rectangles.

tell application id "com.adobe.indesign"

  tell active document

  set every_t to every text frame

  set total_W_x_H to 0

  repeat with this_TextFrame in every_t

  set geo_bounds to 0

  set this_W to 0

  set this_H to 0

  set this_W_x_H to 0

  set geo_bounds to geometric bounds of this_TextFrame

  -- H

  set this_H to ((item 3 of geo_bounds) - (item 1 of geo_bounds))

  set this_W to ((item 4 of geo_bounds) - (item 2 of geo_bounds))

  set this_W_x_H to (this_H * this_W)

  set total_W_x_H to (total_W_x_H + this_W_x_H)

  end repeat

  return total_W_x_H

  end tell

end tell

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
Advocate ,
Jul 03, 2019 Jul 03, 2019

Yes, correct.

Now you are one step behind taking your area of all textframes to a local variable more like an array and return it to main function, you will get array of all textframes area.

Then you can utilize it as per your need going through a loop for each value of array taking one by one the area of your text farmes.

Best

Sunil

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
Advocate ,
Jul 03, 2019 Jul 03, 2019

Hi jalbert_ecwpress ,

I am not that good at applescript, but this might be solution for you.

set list_Of_Text_Frame_Area to {}

tell application id "com.adobe.indesign"

  tell active document

  set every_t to every text frame

  set total_W_x_H to 0

  repeat with this_TextFrame in every_t

  set geo_bounds to 0

  set this_W to 0

  set this_H to 0

  set this_W_x_H to 0

  set geo_bounds to geometric bounds of this_TextFrame

  set this_H to ((item 3 of geo_bounds) - (item 1 of geo_bounds))

  set this_W to ((item 4 of geo_bounds) - (item 2 of geo_bounds))

  set this_W_x_H to (this_H * this_W)

  set total_W_x_H to (total_W_x_H + this_W_x_H)

  -- copy one by one area into list

  copy total_W_x_H to end of list_Of_Text_Frame_Area

  ----------------

  end repeat

  end tell

end tell

-- Here you can utilize this list_Of_Text_Frame_Area

Best

Sunil

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
New Here ,
Jul 04, 2019 Jul 04, 2019

Thank you this worked perfectly.

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
Participant ,
Jul 05, 2019 Jul 05, 2019

Wow, your Correct Answer code looks a lot like mine.

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
Advocate ,
Jul 05, 2019 Jul 05, 2019
LATEST

I took your code only just put list into 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
New Here ,
Jul 04, 2019 Jul 04, 2019

Thanks this is what I needed!

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