Hi there,
I’m working on a book project.
I’m drawing schematics with Omnigraffle.
I’ll have two languages schematics, and I’d like to make the workflow easy so,
I have one file with all my schematics as canvas. So If I have 100 schematics for my book, I’ll have 100 canvas
One canvas = 4 layers:
- 1 layer named FR & 1 named EN which are the text annotations translated
- 1 layer named Image which contains the common parts
- 1 calque named Frame which contains a frame.
I need a script which I run and which:
for each canvas, export 2 pngs:
- 1 named upon the Canvas named + “_EN” with all layer EN + Image + Frame visible (all objects selected)
- 1 named upon the Canvas named + “_FR” with all layer FR+ Image + Frame visible (all objects selected)
I read a lot the AppleScript Dictionnary for functions and syntax and wrote this one :
-- Define the fixed paths for the OmniGraffle file and export folders
set omnigraffleFilePath to "/Users/julien/DATA/TestScript/Schemas.graffle"
set exportFolderFR to "/Users/julien/DATA/TestScript/FR"
set exportFolderEN to "/Users/julien/DATA/TestScript/EN"
-- Open OmniGraffle and the diagram file
tell application "OmniGraffle"
-- Open the OmniGraffle file
open omnigraffleFilePath
set currentDocument to front document
-- Iterate through each canvas in the document
repeat with i from 1 to count of canvases of currentDocument
set currentCanvas to canvas i of currentDocument
set canvasName to name of currentCanvas
-- Export FR: Make FR, Images, and Frame layers visible
tell currentCanvas
-- Hide all layers
repeat with j from 1 to count of layers of currentCanvas
set visible of layer j of currentCanvas to false
end repeat
-- Show only the layers necessary for FR export
set visible of layer "FR" of currentCanvas to true
set visible of layer "Images" of currentCanvas to true
set visible of layer "Frame" of currentCanvas to true
-- Define the export path for FR (POSIX format)
set exportPathFR to exportFolderFR & "/" & canvasName & "_FR.png"
-- Export settings: scale, resolution, region size, border, etc.
set exportProperties to {scale:1.0, resolution:300.0, regionorigin:{0, 0}, regionsize:{1440, 1080}, includeborder:true, borderamount:10, htmlimagetype:"png", readonly:true, drawsbackground:true, copylinkedimages:true, useartboards:false}
-- Export with all the necessary parameters
export currentCanvas to file exportPathFR as "PNG" with properties exportProperties
end tell
-- Export EN: Make EN, Images, and Frame layers visible
tell currentCanvas
-- Hide all layers
repeat with j from 1 to count of layers of currentCanvas
set visible of layer j of currentCanvas to false
end repeat
-- Show only the layers necessary for EN export
set visible of layer "EN" of currentCanvas to true
set visible of layer "Images" of currentCanvas to true
set visible of layer "Frame" of currentCanvas to true
-- Define the export path for EN (POSIX format)
set exportPathEN to exportFolderEN & "/" & canvasName & "_EN.png"
-- Export with the necessary parameters
export currentCanvas to file exportPathEN as "PNG" with properties exportProperties
end tell
end repeat
-- Close the document after export
close currentDocument
end tell
-- Display a notification for export completion
display dialog "Export completed in folders: " & exportFolderFR & " and " & exportFolderEN
I run it. AppleScript throws me an exception:
Omnigraffle error: an export parameter is missing
Would someone help me here ?
If the JS way can be used, I can also give it a try :-)
Best regards,
Julien B.