Author Topic: Geometric Bounds out of order  (Read 398 times)

0 Members and 1 Guest are viewing this topic.

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Geometric Bounds out of order
« on: May 04, 2016, 03:57:08 PM »
I'm getting the location (measurements) for guides on a page and I'm creating text boxes for the areas within the guides. I'm using variables to calculate the text box bounds based on the page size and guide location. For some reason when I do this, the bounds end up in the wrong order. Then the box is in the wrong spot and it's the wrong size.  When I use actual numbers for the geometric bounds {"4 in", "5 in", "6 in", 7 in"} the bounds remain in the right order.  Any ideas?  Thanks!

Code: [Select]
on open droppedfiles
repeat with afile in droppedfiles
tell application "Adobe InDesign CC 2014"

--SETTING MEASUREMENTS TO INCHES
tell view preferences
--Measurement unit choices are:
--picas, points, inches, inches decimal, millimeters, centimeters, or ciceros
--Set horizontal and vertical measurement units to points.
set horizontal measurement units to inches
set vertical measurement units to inches

end tell


open afile


tell document 1

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

--SETTING RULER ORIGIN TO ZERO
set rulerOrigin to ruler origin of view preferences
if rulerOrigin is not page origin then set ruler origin of view preferences to page origin --(spread origin/page origin/spine origin)


set rulerZeroPoint to zero point
if rulerZeroPoint is not {0, 0} then set zero point to {0, 0}

--Do Stuff

--Reset zero point and ruler origin
set zero point to rulerZeroPoint
set ruler origin of view preferences to rulerOrigin

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

--SETTING PAGE HEIGHT AND WIDTH
tell page 1
set pageHeight to item 4 of bounds
set pageWidth to item 3 of bounds
end tell

set theGuides to every guide of page 1

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

--CREATING EMPTY LISTS TO ADD TO LATER ON
set theGuideListVertical to {}
set theGuideListHorizontal to {}

--GETTING THE ORIENTATION (HORIZONTAL OR VERTICAL) FOR EVERY GUIDE
repeat with aGuide in theGuides --Telling it to loop through every guide
set guideOrientation to orientation of aGuide as string --Getting the orientation of every guide

--STORING THE LOCATION (MEASUREMENTS) OF EVERY VERTICAL GUIDE IN ONE LIST
if guideOrientation contains "«constant ****vert»" then --Determining if guides are vertical
set guideLocationVertical to location of aGuide --Getting the location of every guide
set theGuideListVertical to theGuideListVertical & guideLocationVertical --Creating the list with every location (measurement) of all the vertical guides

--STORING THE LOCATION (MEASUREMENTS) OF EVERY HORIZONAL GUIDE IN ANOTHER LIST
else if guideOrientation contains "«constant ****horz»" then --Determining if guides are horizontal
set guideLocationHorizontal to location of aGuide --Getting the location of every guide
set theGuideListHorizontal to theGuideListHorizontal & guideLocationHorizontal --Creating the list with every location (measurement) of all the horizontal guides
end if

end repeat


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

--GETTING GEOMETRIC BOUNDS FOR LAST BOX

set lastFrameVerticalOffset to item 1 of theGuideListHorizontal as number
set lastFrameHorizontalOffset to item 1 of theGuideListVertical as number
set lastFrameHeight to (pageHeight - lastFrameHorizontalOffset) as number
set lastFrameWidth to (pageWidth - lastFrameVerticalOffset) as number

display dialog lastFrameVerticalOffset & " " & lastFrameHorizontalOffset & " " & lastFrameHeight & " " & lastFrameWidth as string

set xFrame1 to make text frame at page 1 of spread 1 with properties {geometric bounds:{lastFrameVerticalOffset, lastFrameHorizontalOffset, lastFrameHeight, lastFrameWidth}}

display dialog geometric bounds of xFrame1 as string

end tell
end tell

end repeat
end open

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: Geometric Bounds out of order
« Reply #1 on: May 04, 2016, 04:51:51 PM »
Ah, I see. InDesign calculates the geometric bounds differently than I thought. Here's the working code. I may be back. I have to figure out how to calculate the placement for the rest of the boxes and then I'm going to measure the square inches of the boxes and put that information in the box.

Code: [Select]
on open droppedfiles
repeat with afile in droppedfiles
tell application "Adobe InDesign CC 2014"

--SETTING MEASUREMENTS TO INCHES
tell view preferences
--Measurement unit choices are:
--picas, points, inches, inches decimal, millimeters, centimeters, or ciceros
--Set horizontal and vertical measurement units to points.
set horizontal measurement units to inches decimal
set vertical measurement units to inches decimal

end tell


open afile


tell document 1

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

--SETTING RULER ORIGIN TO ZERO
set rulerOrigin to ruler origin of view preferences
if rulerOrigin is not page origin then set ruler origin of view preferences to page origin --(spread origin/page origin/spine origin)


set rulerZeroPoint to zero point
if rulerZeroPoint is not {0, 0} then set zero point to {0, 0}

--Do Stuff

--Reset zero point and ruler origin
set zero point to rulerZeroPoint
set ruler origin of view preferences to rulerOrigin

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

--SETTING PAGE HEIGHT AND WIDTH
tell page 1
set pageHeight to item 4 of bounds
set pageWidth to item 3 of bounds
end tell

set theGuides to every guide of page 1

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

--CREATING EMPTY LISTS TO ADD TO LATER ON
set theGuideListVertical to {}
set theGuideListHorizontal to {}

--GETTING THE ORIENTATION (HORIZONTAL OR VERTICAL) FOR EVERY GUIDE
repeat with aGuide in theGuides --Telling it to loop through every guide
set guideOrientation to orientation of aGuide as string --Getting the orientation of every guide

--STORING THE LOCATION (MEASUREMENTS) OF EVERY VERTICAL GUIDE IN ONE LIST
if guideOrientation contains "«constant ****vert»" then --Determining if guides are vertical
set guideLocationVertical to location of aGuide --Getting the location of every guide
set theGuideListVertical to theGuideListVertical & guideLocationVertical --Creating the list with every location (measurement) of all the vertical guides

--STORING THE LOCATION (MEASUREMENTS) OF EVERY HORIZONAL GUIDE IN ANOTHER LIST
else if guideOrientation contains "«constant ****horz»" then --Determining if guides are horizontal
set guideLocationHorizontal to location of aGuide --Getting the location of every guide
set theGuideListHorizontal to theGuideListHorizontal & guideLocationHorizontal --Creating the list with every location (measurement) of all the horizontal guides
end if

end repeat


set hItemListCount to count number of items in theGuideListHorizontal
set vItemListCount to count number of items in theGuideListVertical


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

--GETTING GEOMETRIC BOUNDS FOR LAST BOX

set lastFrameY1 to item 1 of theGuideListHorizontal as number
set lastFrameX1 to item 1 of theGuideListVertical as number


set xFrame1 to make text frame at page 1 of spread 1 with properties {geometric bounds:{lastFrameY1, lastFrameX1, pageWidth, pageHeight}}

display dialog geometric bounds of xFrame1 as string

end tell
end tell

end repeat
end open