Plug-In: Export Canvas Layers
Exports the layers of the current canvas as either individual PNG files, or as images composited from the bottom to the topmost layer. The plug-in uses the current export settings for PNG files.
Return to: OmniGraffle Plug-In Collection
Export Canvas Layers
/*{
"type": "action",
"targets": ["omnigraffle"],
"author": "Otto Automator",
"identifier": "com.omni-automation.og.export-layers-current-vanvas",
"version": "1.1",
"description": "Exports the layers of the current canvas as either individual PNG files, or as images composited from the bottom to the topmost layer.",
"label": "Export Current Canvas Layers",
"shortLabel": "Export Layers",
"paletteLabel": "Export Layers",
"image": "square.3.layers.3d.top.filled"
}*/
(() => {
const action = new PlugIn.Action(async function(selection, sender){
try {
exportOptions = ["Individual Images","Composited Images"]
exportOptionsMenu = new Form.Field.Option(
"exportOption",
null,
[0,1],
exportOptions,
0
)
inputForm = new Form()
inputForm.addField(exportOptionsMenu)
formPrompt = "Choose the export style:"
buttonTitle = "Continue"
formObject = await inputForm.show(formPrompt,buttonTitle)
exportOptionIndex = formObject.values["exportOption"]
cnvs = document.windows[0].selection.canvas
cnvs.layers.forEach(layer => layer.visible = false)
wrappers = new Array()
layerSet = cnvs.layers.slice().reverse()
counter = 0
for (aLayer of layerSet){
aLayer.visible = true
exportName = encodeURIComponent(counter + "-" + aLayer.name)
fileTypeID = "public.png"
wrapper = await document.makeFileWrapper(exportName, fileTypeID)
wrappers.push(wrapper)
if (exportOptionIndex === 0){aLayer.visible = false}
counter = counter + 1
}
cnvs.layers.forEach(layer => layer.visible = true)
filesaver = new FileSaver()
folderType = new FileType("public.folder")
filesaver.types = [folderType, FileType.png, FileType.pdf]
docName = document.name.replace(/\.[^/.]+$/, "")
fldrwrapper = FileWrapper.withChildren(`${docName} Export Folder`, wrappers)
urlObj = await filesaver.show(fldrwrapper)
urlObj.open()
}
catch(err){
if(!err.causedByUserCancelling){
new Alert(err.name, err.message).show()
}
}
});
action.validate = function(selection, sender){
return true
};
return action;
})();