Skip to content

Instantly share code, notes, and snippets.

@jfdeclercq
Last active January 13, 2023 05:50
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfdeclercq/bafb9ddd617a65d4de8453d69cea53be to your computer and use it in GitHub Desktop.
Save jfdeclercq/bafb9ddd617a65d4de8453d69cea53be to your computer and use it in GitHub Desktop.
Export View as image (PNG) with date and diagram name in filename. #jarchi
//Export View as image (PNG) with date and diagram name in filename.
// Get the first view in the model
//var view = $("view").first();
var view = selection.filter("archimate-diagram-model").first();
// Get the Base64 bytes of the view in PNG format. Can use "PNG", "BMP", "JPG" or "GIF"
// Options are scale (1 - 4) and margin (pixel value)
var bytes = $.model.renderViewAsBase64(view, "JPG", {scale: 1, margin: 20});
var date = new Date();
// Ask for a file name
var fileName = window.promptSaveFile( { title: "Save View", filterExtensions: [ "*.jpg" ], fileName: ""+ date.toISOString().replace(":","").replace("T","-").slice(0,15)+ "-" + view.name + ".jpg" } );
if(fileName) {
// Write to file
$.fs.writeFile(fileName, bytes, "BASE64");
}
@projetnumero9
Copy link

Hi,
just for sharing, based on a post on the archimatetool forum, I wrote:

// Based on: https://gist.github.com/jfdeclercq/bafb9ddd617a65d4de8453d69cea53be 
//  
// Select a folder in the model tree before running this script.  
// User will be prompted to confirm name and target folder to save exported view in .JPG format
//
  
// # Main  
// Clear the console for any new message which may occur  
console.show();  
console.clear();  
$(selection.first()).children().each(function(o){  
    var bytes = $.model.renderViewAsBase64(o, "JPG", {scale: 1, margin: 20});
    var date = new Date();
    // Ask for a file name
    var fileName = window.promptSaveFile( { title: "Save View", filterExtensions: [ "*.jpg" ], fileName: ""+ date.toISOString().replace(":","").replace("T","-").slice(0,15)+ "-" + o.name + ".jpg" } );
    if(fileName) {
        // Write to file
        $.fs.writeFile(fileName, bytes, "BASE64");
    }
});

Thanks for your original idea,
Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment