InDesign CS6 Applescript Basic Questions

I have previously scripted Quark Xpress to do some automation for me, but I am having such a stumbling block with ID CS6. I would like to accomplish a number of items

task 1,

I need to prompt for a 6 digit number, then open an existing 3 page template document, then draw a graphic box on each page and import a PDF into each box. Then I need to save the file into a specific folder location based on the number provided.

task 2,

I need to take the graphic box on page 3 of a document, copy it to page 2, position the box in a specific location based on the upper left corner, resize the box, then rotate the box based on the center point. Ideally I then need to position the graphic INSIDE the graphic box to specific coordinates.

For some reason, I can’t even write the correct statement to open the existing template file.

Is there anyone out there willing to help me through this?
thanks
david

I have a few questions to try to help you:

In your task 1, the graphic box on each page will be at the same position and size? The PDF that will be imported is the same too? always the same predefined PDF or the user will have choose it?

I can give you a detailed description…

This script’s goal will be to set up a 3 page proof that I will write to a PDF and email to the customer.
The proof consists of page 1, where I will need to import the ART SIGNATURE PDF file. Page 2 gets the BARCODE SIGNATURE PDF imported, and page 3 gets a BARCODE SHEET PDF imported.

Because of the nature of every, I only need to create a 8.5" x 4" box to import the ART and BARCODE SIGNATURE PDFs into. I am only interested in seeing the top half of those PDFS. So I need to be able to import them and have them postioned flush to the left and top of the graphic container.

Page 3, I will need to create an 8.5" x 11" graphic container that will receive the BARCODE SHEET PDF. For starters, this graphic will always be 8.5 x 11 in size. One thing that I have noticed doing this manually, is that I had to specific what the bounding area of the PDF object was. Originally, I didn’t realize that, and when we imported the barcode sheet, it wouldn’t fill the page. So that’s something I need to keep in mind, by what bounding box is being used to import the PDF.

All three of the PDFs to be imported will be based on the job number provided at the beginning. That will be stored as a variable and the path will be something like: serverName:PDFProofs:JOBnumber:
then I will need to say something like:

on page 1, create a box that is 8.5 x 4 and import into that box, the PDF in the folder whose name contains “ART”. If this isn’t found, display dialog “ART not found” and then go to page 2

on page 2, create a box that is 8.5 x 4 and import into that box, the PDF in the folder whose name contains “BC”. If this isn’t found, display dialog “BC not found” and then go to page 3

on page 3, create a box that is 8.5 x 11 and import into that box, the PDF in the folder whose name contains “SHEET”. If this isn’t found, display dialog “SHEET not found” and then save this file into the folder SERVER:WorkFiles:JobNumber as a file called “JobNumber” & “PROOF”

I have an existing script that works for QuarkXpress that does this exact routine, I just can’t wrap my head around the coding for making this happen in InDesign. Would you like to see that file?

thanks ever so much
David

ever googled for ‘Indesign Scriptingguide Applescript’ ¿

Try to learn scripting ID and then ask questions to posted code!

My 50 Cent :slight_smile:

i have… and i have the scripting manuals, but the coding seems much more complex than what it was for indesign. I am not a programmer, just a graphic designer trying to automate part of the mundane work.

david

Ok… progess…
I am simply trying to rotate a rectangle I have created


tell application "Adobe InDesign CS6"
	activate
	
	--open file "Macintosh HD:Users:david:Desktop:pdf-generic.indd"
	set myDocument to make document
	tell view preferences of myDocument
		set vertical measurement units to inches
		set horizontal measurement units to inches
	end tell
	tell page 1 of myDocument
		set myRectangle to make rectangle with properties {geometric bounds:{3, 3, 4, 4}, stroke weight:0}
		select all page items of page 1 of myDocument
		set myRotateMatrix to make transformation matrix with properties {counterclockwise rotation angle:27}
		transform myRectangle in pasteboard coordinates from center anchor with matrix myRotateMatrix
	end tell
end tell

But this gives me an error:

error “Adobe InDesign CS6 got an error: Can’t make class transformation matrix.” number -2710 from transformation matrix to class

I did copy that pretty much directly from the AS Guide… so I’m not sure why it’s giving me that type of error.

david

You’re getting that error because you’re telling a page to make the matrix, not the application. Move the “make transformation matrix…” line outside the “tell page 1” block.

LMAO!!! Ok, so I quickly moved the statement out of the page level, and tried it… HAH! It rotated the whole document page… pretty funny looking. I’m guessing that I can’t use “pasteboard coordinates” here. Where would THAT ever be used?

david

Grrrr… this is what I hate…

I move it out… the script runs, but not the result that I expect. The document page itself is rotating and the item that I created is staying put. I want it the other way around, leave that document page oriented at 0 degrees and then rotate the box itself.

Here’s what I have…

tell application "Adobe InDesign CS6"
	activate
	
	--open file "Macintosh HD:Users:david:Desktop:pdf-generic.indd"
	set myDocument to make document
	tell view preferences of myDocument
		set vertical measurement units to inches
		set horizontal measurement units to inches
	end tell
	set myRotateMatrix to make transformation matrix with properties {counterclockwise rotation angle:27}
	tell page 1 of document 1
		set myRectangle to make rectangle with properties {geometric bounds:{3, 3, 4, 4}, stroke weight:0}
		select all page items of page 1 of myDocument
		transform item 1 in page coordinates from center anchor with matrix myRotateMatrix
	end tell
end tell

My next step also will be trying to figure out the syntax for inserting a graphic into the box.

david

g’day
this will do the two things you are trying to accomplish, you will need to put in error checking etc

tell application "Adobe InDesign CS6"
	activate
	set myDoc to make document
	tell view preferences of myDoc
		set vertical measurement units to inches
		set horizontal measurement units to inches
	end tell
	----
	set myRotateMatrix to make transformation matrix with properties {counterclockwise rotation angle:27}
	tell page 1 of myDoc
		set myRectangle to make rectangle with properties {geometric bounds:{3, 3, 4, 4}, stroke weight:0}
		--select all page items of page 1 of myDoc
		transform myRectangle in pasteboard coordinates from center anchor with matrix myRotateMatrix
	end tell
	----
	set mySpread to spread 1 of myDoc
	tell mySpread
		set _PDF to "Macintosh HD:Users:Budgie:Desktop:Test1.pdf"
		place (_PDF) as alias on myRectangle
		fit rectangle 1 given center content
	end tell
	----
end tell

I think this may help to get where your trying to be, it’s a bit messy, but it’s a start

tell application "Adobe InDesign CS6"
	activate
	tell view preferences
		set vertical measurement units to inches
		set horizontal measurement units to inches
	end tell
	set JobNumber to text returned of (display dialog "Enter Job Number" default answer "")
	set JobNumber to JobNumber & "-PROOF"
	set myDoc to make new document with properties {document preferences:{pages per document:3, page width:12, page height:9, facing pages:false}}
	-----------------------------------------
	---- PAGE 1
	-----------------------------------------
	tell page 1 of myDoc
		set {a, b, c, d} to bounds of page 1 of myDoc
		set myRectangle to make rectangle with properties {geometric bounds:{0, 0, 8.5, 4}, stroke weight:0}
		set {w, x, y, z} to geometric bounds of myRectangle
		move myRectangle by {(d / 2 - (x + z) / 2), (c / 2 - (w + y) / 2)}
		try
			set mySpread to spread 1 of myDoc
			tell mySpread
				set _folders to "Macintosh HD:Users:Budgie:Desktop:ART:"
				tell application "Finder"
					set aFolder to _folders
					set aPath to (aFolder as text)
					set srcfolder to aPath
					set _PDF to every item of folder srcfolder whose name is JobNumber & ".pdf"
				end tell
				place (_PDF) as alias on myRectangle
				fit rectangle 1 given center content
			end tell
		on error
			display dialog "Art not found." giving up after 2
		end try
	end tell
	-----------------------------------------
	---- PAGE 2
	-----------------------------------------
	tell page 2 of myDoc
		set {a, b, c, d} to bounds of page 2 of myDoc
		set myRectangle to make rectangle with properties {geometric bounds:{0, 0, 8.5, 4}, stroke weight:0}
		set {w, x, y, z} to geometric bounds of myRectangle
		move myRectangle by {(d / 2 - (x + z) / 2), (c / 2 - (w + y) / 2)}
		try
			set mySpread to spread 2 of myDoc
			tell mySpread
				set _folders to "Macintosh HD:Users:Budgie:Desktop:BC:"
				tell application "Finder"
					set aFolder to _folders
					set aPath to (aFolder as text)
					set srcfolder to aPath
					set _PDF to every item of folder srcfolder whose name is JobNumber & ".pdf"
				end tell
				place (_PDF) as alias on myRectangle
				fit rectangle 1 given center content
			end tell
		on error
			display dialog "BC not found." giving up after 2
		end try
	end tell
	-----------------------------------------
	---- PAGE 3
	-----------------------------------------
	tell page 3 of myDoc
		set {a, b, c, d} to bounds of page 3 of myDoc
		set myRectangle to make rectangle with properties {geometric bounds:{0, 0, 8.5, 11}, stroke weight:0}
		set {w, x, y, z} to geometric bounds of myRectangle
		move myRectangle by {(d / 2 - (x + z) / 2), (c / 2 - (w + y) / 2)}
		try
			set mySpread to spread 3 of myDoc
			tell mySpread
				set _folders to "Macintosh HD:Users:Budgie:Desktop:SHEET:"
				tell application "Finder"
					set aFolder to _folders
					set aPath to (aFolder as text)
					set srcfolder to aPath
					set _PDF to every item of folder srcfolder whose name is JobNumber & ".pdf"
				end tell
				place (_PDF) as alias on myRectangle
				fit rectangle 1 given center content
			end tell
		on error
			display dialog "Sheet not found." giving up after 3
			tell application "Adobe InDesign CS6"
				set myDesktopFolder to "Macintosh HD:Users:Budgie:Desktop:SAVE FILES:"
				set myFile to myDesktopFolder & JobNumber
				save myDoc to myFile
				close myDoc saving yes
			end tell
		end try
	end tell
	-----------------------------------------
	----
	-----------------------------------------
end tell