Script to export a portion of all canvases and save a series of PNGs

Hello,

I am not a huge coder, but have pieced together a script to save out a canvas as a series of png’s.

However it is not working perfecty and grabs only a small elements on some pages and the whole canvas on others.

What I want to do is to get a specific region of each canvas as you can in the export as Dialouge in file/export as. i.e.

Can anyone help me edit this script to do that?

This is my current script

----------start ----------
-Choose the output folder. Script ends if cancelled
set strOutputDirectory to choose folder

–Get the name of the current file
tell application “OmniGraffle”
set objOmniGraffleFile to front document
set strOmniGraffleFileName to name of objOmniGraffleFile as string
end tell

–Drop the file extension
set strOmniGraffleFileNameNoExtension to remove_extension(strOmniGraffleFileName)

–Export each canvas
tell application “OmniGraffle”
–Initialise
set objOmniGraffleFile to front document
set canvas of front window to canvas 1 of objOmniGraffleFile
set intCanvasCount to count of canvases of objOmniGraffleFile

--Iterate through each canvas and export it to the specified folder
--File name will be the file name of the file with a hyphen and then the name of the canvas
--Files saved in PNG format
repeat with intCurrentCanvasID from 1 to intCanvasCount
	set canvas of front window to canvas intCurrentCanvasID of objOmniGraffleFile
	set currentCanvas to canvas of front window
	set strOutputFilePath to strOutputDirectory & strOmniGraffleFileNameNoExtension & " - " & name of currentCanvas & ".png" as string
	save objOmniGraffleFile as "png" in (strOutputFilePath)
end repeat

end tell

–Display a final message about the exports
display dialog "Exported " & intCanvasCount & " files to
" & strOutputDirectory with title “Export Complete”

– Remove file extension (from http://www.macosxautomation.com/applescript/sbrt/)
on remove_extension(this_name)
if this_name contains “.” then
set this_name to ¬
(the reverse of every character of this_name) as string
set x to the offset of “.” in this_name
set this_name to (text (x + 1) thru -1 of this_name)
set this_name to (the reverse of every character of this_name) as string
end if
return this_name
end remove_extension

----------End ------------

Thanks for any advice

Not sure if you’re still interested, but I needed the same thing and ended up writing a script for myself.

set strOutputDirectory to choose folder
tell application id “OGfl”
set objOmniGraffleFile to front document
set canvas of front window to canvas 1 of objOmniGraffleFile
set intCanvasCount to count of canvases of objOmniGraffleFile

set theNumber to 1

--Iterate through each canvas and export it to the specified folder
--File name will be the file name of the file with a hyphen and then the name of the canvas
--Files saved in PNG format
repeat with intCurrentCanvasID from 1 to intCanvasCount
	set canvas of front window to canvas intCurrentCanvasID of objOmniGraffleFile
	set currentCanvas to canvas of front window
	set strOutputFilePath to strOutputDirectory & (theNumber) & " - " & name of currentCanvas & ".png" as string
	set area type of current export settings to manual region
	set origin of current export settings to {18.8333, 117.5}
	set size of current export settings to {495.1111, 278.5}
	save objOmniGraffleFile as "png" in file (strOutputFilePath)
	set theNumber to theNumber + 1
end repeat

end tell
–Display a final message about the exports
display dialog "Exported " & intCanvasCount & " files to
" & strOutputDirectory with title “Export Complete”

All you need to do is change the values of origin and size to the particular values you need. Origin should be set to the top left corner of the area you want and the size should be set to how big of an area you want.

Hopefully that helps someone else!