Geometric Bounds help needed in applescript for text box placement

Explorer ,
Jul 27, 2022 Jul 27, 2022

Copy link to clipboard

Copied

I have a line in my applescript to set a text box at a certain area on the document.

 

Is it possible to set it so that it starts the box point in the lower left of the page?

 

I am trying to either get it to NOT go off the bottom of the page

OR

Just set all 4 corners at a specific location on the page.

Page sizes can vary.

 

set slugText to make new text frame with properties {geometric bounds:{(item 4 of page 1's bounds), 0.25, ((item 1 of page 1's bounds) + 1.5), 2}, stroke color:"noprint", stroke weight:1, item layer:"Job Info - Non-Print"}

TOPICS
Scripting

Views

191

Likes

Translate

Translate

Report

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

Community Expert , Aug 01, 2022 Aug 01, 2022

Try this—note you have not set your rulers in the script so this wont work if they are set to anything other than inches:

 

 

tell application id "com.adobe.indesign"
	tell active document
		set zero point to {0, 0}
		delete unused swatches
		set allSwatches to every swatch
		try
			set noprint to make color with properties {model:spot, space:CMYK, color value:{100, 0, 0, 0}, name:"noprint"}
		on error
			set noprint to every color whose name is "noprint"
		end try
		
		try
			wb to make color w
...

Likes

Translate

Translate
Community Expert ,
Jul 27, 2022 Jul 27, 2022

Copy link to clipboard

Copied

Hi @denisep726548, I'm not very skilled in applescript, but see if this helps:

tell application "Adobe InDesign 2022"
	
	set doc to active document
	set page1 to page 1 of doc
	tell page1 to set slugText to make new text frame with properties {layer:layer "Job Info - Non-Print" of doc}
	
	set textFrameHeight to 1.5
	set leftMargin to 0.5
	set rightMargin to 0.5
	set bottomMargin to 0.25
	
	tell slugText
		
		set geometric bounds to {(item 3 of bounds of page1) - textFrameHeight - bottomMargin, leftMargin, (item 3 of bounds of page1) - bottomMargin, (item 4 of bounds of page1) - rightMargin}
		set stroke color to "noprint"
		set stroke weight to 1
		
	end tell
	
end tell

 - Mark

Likes

Translate

Translate

Report

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
Community Expert ,
Jul 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

Is it possible to set it so that it starts the box point in the lower left of the page?

 

Hi @denisep726548 , Marks’s script is placing the frame to the lower left margin, this would make a 2" x 1" frame placed in the lower left corner. Also, when setting dimensions you’ll need to set the scripting units or ruler units, otherwise the document’s current ruler units will determine what 144 means.

 

tell application id "com.adobe.indesign"
	set measurement unit of script preferences to points
	tell active document
		tell page 1
			set y to item 3 of bounds
			set fw to 144
			set fh to 72
			set slugText to make new text frame with properties {geometric bounds:{y - fh, 0, y, fw}, stroke color:"Black", stroke weight:1}
		end tell
	end tell
end tell

 

Likes

Translate

Translate

Report

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
Community Expert ,
Jul 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

Also, if you want to fit the constructed text frame into the actual document slug

tell application id "com.adobe.indesign"
	set measurement unit of script preferences to points
	tell active document
		--set the bottom slug dimension to 1"
		set slug bottom offset of document preferences to 72
		
		--get the document's bottom bleed
		set bo to document bleed bottom offset of document preferences
		
		--the frame’s height
		set fh to slug bottom offset of document preferences
		
		tell page 1
			--the top of the text frame
			set y to (item 3 of bounds) + bo
			
			--the width of the text frame
			set fw to (item 4 of bounds) * 0.5
			
			set slugText to make new text frame with properties {geometric bounds:{y, 0, y + fh - bo, fw}, stroke color:"Black", stroke weight:1}
		end tell
	end tell
end tell

 

 

Screen Shot 27.png

Likes

Translate

Translate

Report

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 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

I actually need Mark's script to do what it is doing, but just make the box a certain width, rather than a negative number away from the right margin. Like tell it to be 2" wide all the time.

I DO want it on the page rather than in the slug area. I think I need a combo of what you both said.

Likes

Translate

Translate

Report

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 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

Here is my entire script 

 

tell application "Adobe InDesign 2022"

 

tell the active document

 

delete unused swatches

set allSwatches to every swatch

try

set noprint to make color with properties {model:spot, space:CMYK, color value:{100, 0, 0, 0}, name:"noprint"}

on error

set noprint to every color whose name is "noprint"

end try

try

wb to make color with properties {model:spot, space:CMYK, color value:{0, 0, 0, 100}, name:"wb"}

on error

set wb to every color whose name is "wb"

end try

try

set infoLayer to make layer with properties {name:"Job Info - Non-Print", printable:true, layer color:blue}

on error

set infoLayer to every layer whose name is "Job Info - Non-Print"

end try

 

set ul to return & "Ink Color(s):" & return

set ds to {"None", "Registration", "Paper", "noprint", "wb", "die", "white"}

delete every page item of item 1 of infoLayer

repeat with x in allSwatches

if name of x is not in ds then

set ul to ul & name of x & return

end if

end repeat

 

set slugText to make new text frame with properties {geometric bounds:{(item 4 of page 1's bounds), 0.25, ((item 1 of page 1's bounds) + 1.5), 2}, stroke color:"noprint", stroke weight:1, item layer:"Job Info - Non-Print"}

set contents of slugText to ul

set contents of slugText to ul

set fill color of text 1 of slugText to "noprint"

set overprint fill of text 1 of slugText to true

set applied font of text 1 of slugText to "Helvetica LT Std"

set font style of text 1 of slugText to "Condensed"

set first line indent of text 1 of slugText to 0.125

set overprint stroke of slugText to true

set Text_Frame to item 1 of (every text frame whose label is "slugText")

 

tell slugText

 

set theLines to every line

 

 

 

--get maxLineLength

 

set maxLength to null

 

repeat with i from 1 to count of theLines

 

set {start, stopp} to {horizontal offset of line i, end horizontal offset of line i}

 

set currentLineLength to stopp - start

 

if i is 1 then

 

set maxLength to currentLineLength

 

else

 

if currentLineLength is greater than maxLength then

 

set maxLength to currentLineLength

 

end if

 

end if

 

end repeat

 

 

 

--set x2-bounds of Text_Frame

 

set {y1, x1, y2, x2} to visible bounds

 

set visible bounds to {y1, x1, y2, x1 + maxLength + 0.25}

 

--fit height

 

fit given frame to content

 

 

end tell

 

end tell

 

end tell

 

 

Likes

Translate

Translate

Report

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 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

....and I would like the end result to look something like this, but the lower left corner of the text box stays in place and will flex as more lines are added to it.

 

Screen Shot 2022-07-28 at 10.50.54 AM.png

Likes

Translate

Translate

Report

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
Community Expert ,
Jul 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

The bounds array is {Y1(top), X1(left), Y2(bottom), X2(right)} relative to the rulers zero point (normally the upper left corner of the page, unless it’s been changed). So a 2" width is {Y1, X1, Y2, X1+2}, assuming the rulers are set to inches.

 

Why isn‘t your printer just running a preflight, both InDesign’s and AcrobatPro’s preflights will report document ink colors. If you Package from ID, the Package Info also lists used ink colors.

Screen Shot 34.png

 

Likes

Translate

Translate

Report

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 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

Thank you! I changed this {y1, x1, y2, x1 + maxLength + 0.25} to {y1, x1, y2, x1 + 2} and it works as I would like it to.

We are the printer and are putting the info on our proof for the CSR and Customer. Doing a preflight report does not make sense in this case for our purpose in prepress. Thank you.

Likes

Translate

Translate

Report

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
Community Expert ,
Jul 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

What would happen if the client’s using the Color Picker and all the page colors are unnamed?

 

Screen Shot 35.png

Likes

Translate

Translate

Report

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 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

That would never happen for us. We do all the file prep and ensure all the color seps are correct before printing.

Likes

Translate

Translate

Report

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 ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

So does anyone know how to have it read the bottom of the text frame (after I fit it to the text line height) and move it back to .25 from the bottom margin?

Likes

Translate

Translate

Report

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
Community Expert ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

Try this—note you have not set your rulers in the script so this wont work if they are set to anything other than inches:

 

 

tell application id "com.adobe.indesign"
	tell active document
		set zero point to {0, 0}
		delete unused swatches
		set allSwatches to every swatch
		try
			set noprint to make color with properties {model:spot, space:CMYK, color value:{100, 0, 0, 0}, name:"noprint"}
		on error
			set noprint to every color whose name is "noprint"
		end try
		
		try
			wb to make color with properties {model:spot, space:CMYK, color value:{0, 0, 0, 100}, name:"wb"}
		on error
			set wb to every color whose name is "wb"
		end try
		try
			set infoLayer to make layer with properties {name:"Job Info - Non-Print", printable:true, layer color:blue}
		on error
			set infoLayer to every layer whose name is "Job Info - Non-Print"
		end try
		
		set ul to return & "Ink Color(s):" & return
		set ds to {"None", "Registration", "Paper", "noprint", "wb", "die", "white"}
		delete every page item of item 1 of infoLayer
		repeat with x in allSwatches
			if name of x is not in ds then
				set ul to ul & name of x & return
			end if
		end repeat
		tell page 1
			set os to 0.25
			set {a, b, c, d} to bounds
			--makes the text frame with an initial bounds set to the the page dimensions with the list as the contents
			set slugText to make new text frame with properties {geometric bounds:{a, os, c, d}, stroke color:"noprint", stroke weight:1, item layer:"Job Info - Non-Print", contents:ul}
			tell slugText
				--fits the text frame to the contents
				fit given frame to content
				--set the properties of the text
				set properties of text 1 to {fill color:"noprint", overprint fill:true, first line indent:os * 0.5, applied font:"Helvetica LT Std", font style:"Condensed"}
				--get the frame’s adjusted bounds
				set {e, f, g, h} to geometric bounds
				--the frame’s height
				set h to (g - e) + os
				
				--get the longest line
				set ho to 0
				repeat with z in lines
					if horizontal offset of last character of z is greater than ho then
						set w to horizontal offset of last character of z
					end if
					set ho to horizontal offset of last character of z
				end repeat
				--set the bounds to the lower left
				set geometric bounds to {c - h, f, c - os, w + os}
			end tell
		end tell
	end tell
end tell

 

 

Screen Shot 3.png

Likes

Translate

Translate

Report

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 ,
Aug 02, 2022 Aug 02, 2022

Copy link to clipboard

Copied

LATEST

Again. Thank you!

Likes

Translate

Translate

Report

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 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

I mean, it still doesnt completely do what I want, but I might be able to mess with it and try and figure it out.

Likes

Translate

Translate

Report

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

Save time with Adobe Express quick actions