I’m trying to add two text frames above the selected artwork of an Illustrator CC document, then add them to the selection, and print the whole lot.
I’m using the GUI to print, so the end user can set the Print Dialog box to whatever parameters they require.
I cannot work out how to add the two text frames to the selection, and cannot find anything on the net, or in the Applescript pdf for Illustrator. My two attempts crash.
property actualPrintableJobsCounter : 0
property theItem : ((path to desktop) & "No.1 Appolo (180ml Front)_ Stamping Die_21-07-15.ai" as text) # as alias
property tempName : ""
property tempNameExtension : ""
property didItPrint : false
property errorMessage : ""
property sayEveryErrorMessage : true
property runForOZ : true
property voiceSetter : "Vicki"
property theLargePagePrinter : "Large Page Printer"
property PreserveFileName : ""
property theJobsTally : 0
property ftpPrintFlag : false
property mailReadyToSend : false
property extensionName : ""
property saveftpFiles : false
property attachmentBarCodeDateTimeName : "(2015-07-05 121212"
my printIllustrator()
on doFoo(theArtboard)
tell application "Adobe Illustrator" to tell document 1
do _javascript_ ("app.activeDocument.artboards.setActiveArtboardIndex(" & theArtboard & ")")
end tell
end doFoo
on printIllustrator()
try
set p to 1
tell application "Finder"
set my tempName to name of file (my theItem) as text
set my PreserveFileName to tempName
end tell
tell application id "com.adobe.illustrator" -- Adobe Illustrator
try
activate
repeat until the (count of documents) is 0
close every document saving no
end repeat
set addBarCode to false
set my theItem to my theItem as alias
try
tell application "System Events" to tell process "Adobe Illustrator"
try
keystroke return
end try
end tell
open my theItem dialogs no -- as alias (don't use 'as alias' or routine won't work)
end try
repeat 2 times
tell application "System Events" to tell process "Adobe Illustrator"
try
click button "Continue" of window 1
end try
try
keystroke return
end try
end tell
end repeat
set x to 0
set foundAFile to false
repeat
if exists document 1 then
set foundAFile to true
exit repeat
end if
do shell script ("sleep 0.2")
set x to x + 1
if x ≥ 400 then exit repeat --try for 40 seconds
end repeat
set addBarCode to false
tell document 1
set n to number of layers
repeat with x from 1 to n
set p to 5
set locked of layer x to false
end repeat
end tell
if my tempName does not contain "_UEI " then set addBarCode to true
set p to 2
if addBarCode then
tell document 1
set p to 2.01
set artBoardCount to count of artboards
#say artBoardCount
end tell
set p to 2.02
set c to current date
repeat with eachArtBoardCounter from 1 to artBoardCount
try
set TempAttachmentName to my ResetAttachmentName()
set eachArtBoard to eachArtBoardCounter
set p to 2.1
do shell script ("sleep 1")
set p to 2.14
tell document 1
set p to 2.15
selectobjectsonactiveartboard
set p to 2.19
fitartboardtoselectedart index (eachArtBoardCounter - 1)
set {xleft, ytop, xright, ybottom} to artboard rectangle of artboard eachArtBoardCounter
end tell
set p to 2.7
set p to 4
#
# Text Frame 1
#
make new text frame in document 1 with properties {name:"AreaText", contents:TempAttachmentName, position:{(xleft + 2), (ytop + 30)}}
set p to 6.1
try
make new character style in document 1 with properties {name:"BarCodeBox"}
end try
set p to 6.2
set the size of character style "BarCodeBox" of document 1 to 10
set p to 6.3
apply character style character style "BarCodeBox" of document 1 to the text range of text frame "AreaText" of document 1
set p to 6.4
set the text font of text range of text frame "AreaText" of document 1 to text font "IDAutomationHC39M"
#
# Text Frame 2
#
make new text frame in document 1 with properties {name:"AreaTextTwo", contents:my PreserveFileName, position:{(xleft + 240), (ytop + 30)}}
set p to 7.1
try
make new character style in document 1 with properties {name:"NameBox"}
end try
set p to 7.2
set the size of character style "NameBox" of document 1 to 16
set p to 7.3
apply character style character style "NameBox" of document 1 to the text range of text frame "AreaTextTwo" of document 1
set p to 7.4
set the text font of text range of text frame "AreaTextTwo" of document 1 to text font "Cochin"
set p to 9
tell document 1
selectobjectsonactiveartboard
set p to 9.1
# Crashes
set selection to selection & text "AreaText"
set p to 9.2
# Crashes
select text frame "AreaTextTwo" with extending selection
set p to 9.3
fitartboardtoselectedart index (eachArtBoardCounter - 1)
end tell
on error errmsg number errnum
set my didItPrint to false
tell application "System Events" to display dialog "printIllustrator CC 2015 " & return & errmsg & return & "number " & errnum & " p = " & p & return & (current date) - c giving up after 40
end try
end repeat
end if
set p to 16
on error errmsg number errnum
set my didItPrint to false
tell application "System Events" to display dialog "printIllustrator " & return & errmsg & return & "number " & errnum & " p = " & p giving up after 40
end try
try
activate
do shell script ("sleep 1")
tell application "System Events" to tell process "Adobe Illustrator"
keystroke "p" using command down
do shell script ("sleep 0.4")
end tell
repeat 15 times
tell application "System Events" to tell process "Adobe Illustrator"
keystroke tab
end tell
do shell script ("sleep 0.05")
end repeat
tell application "System Events" to tell process "Adobe Illustrator"
do shell script ("sleep 0.1")
keystroke (characters 1 through -1 of (my theLargePagePrinter as text)) as text
do shell script ("sleep 0.2")
keystroke return
end tell
repeat 3 times
tell application "System Events" to tell process "Adobe Illustrator"
keystroke tab
end tell
do shell script ("sleep 0.05")
end repeat
tell application "System Events" to tell process "Adobe Illustrator"
do shell script ("sleep 0.1")
keystroke (characters 1 through -1 of (my theLargePagePrinter as text)) as text
do shell script ("sleep 0.2")
keystroke return
try
keystroke return
end try
end tell
end try
do shell script ("sleep 0.5")
end tell
set my theJobsTally to (my theJobsTally) + 1 # Add to printed jobs Tally
#my RenameAttachment(my theItem , TempAttachmentName)
if addBarCode then
if my saveftpFiles then
#tell application "Adobe Illustrator" to set my tempName to name of document 1
set newPath to my setUpSavePath("_UEI ftpSaving") as text
tell application "Adobe Illustrator"
try
save document 1 in file newPath
end try
end tell
set end of my preFlightpdfList to newPath
if my ftpPrintFlag then set my mailReadyToSend to true
end if
end if
# set my didItPrint to true
tell application "Adobe Illustrator"
repeat until the (count of documents) is 0
close every document saving no
end repeat
end tell
on error errmsg number errnum
set my didItPrint to false
my sayTheText("illustrator error")
if errnum = -1728 then
set my errorMessage to my errorMessage & "We struck an Illustrator file that refused to open." & return & "It might be that fonts were missing." & return
if DialogFlag > 0 then set my errorMessage to my errorMessage & "There were " & DialogFlag & " opening dialogs." & return & return
end if
tell application "System Events" to display dialog "printIllustrator " & errmsg & return & errnum giving up after 40
tell application "Adobe Illustrator"
repeat until the (count of documents) is 0
close every document saving no
end repeat
end tell
end try
end printIllustrator
on ResetAttachmentName()
try
set my actualPrintableJobsCounter to ((my actualPrintableJobsCounter) + 1)
on error errmsg
tell application "System Events" to display dialog "Item Printers reset attachments 1 " & my actualPrintableJobsCounter & return & return & errmsg
end try
try
set TheNewName to ((my attachmentBarCodeDateTimeName) & "Z-" & (my actualPrintableJobsCounter) & ")" as text)
return TheNewName
on error errmsg
tell application "System Events" to display dialog "Item Printers reset attachments 2 " & my actualPrintableJobsCounter & return & return & errmsg giving up after 40
return ""
end try
end ResetAttachmentName
on sayTheText(theText)
try
if my voiceSetter as text is "Use voice 'Vicki'" then
say "[[rate " & my ThespeechRate & "]]" & theText using "Vicki" without waiting until completion
else
say theText without waiting until completion
end if
on error errmsg number errnum
tell application "System Events" to display dialog "sayTheText " & errmsg as text giving up after 40
end try
end sayTheText