Export views from a specific Folder

Started by koopie66, March 05, 2021, 15:23:21 PM

Previous topic - Next topic


I want to export views from a specific Folder. I have made a script that does this function based on a selection, but actually I want the folders selected from my script (so not based on the users input)
In Views I have the following folder structure: Views-> Company->General. The views that are in the folder General I want to export   

How can I select this folder and use its contents?

Any Help is appreciated

Kind regards Hans


Based on: https://gist.github.com/jfdeclercq/bafb9ddd617a65d4de8453d69cea53be
, i came up with the following:

// 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 
    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");

Should do the trick, once customized with your code,

Jean-Baptiste Sarrodie


@projetnumero9 : I don't think that what Hans is looking for...

From my understading, you want to know how to select a defined folder from script without user interaction. Here's a snippet for that:


function doSomething(obj) {

function customFilter(obj) {
  return getPath(obj) == "/Views/Company/General";   // Change based on your needs (don't forget leading '/')

function getPath(obj) {
  var pathCollection = $(obj).add($(obj).parents());   // Get a list of object and its parents
  var path = Java.from(pathCollection).reduce(createPath, "");   // Convert the (java) list to a (JS) list and reduce it with the 'createPath' function
  return path;

function createPath(currentPath, currentObject) {
  return "/" + currentObject.name + currentPath;


If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.


Hi JB,

thanks for the snippet, this was indeed the missing part.