Skip to content
Phil Beauvoir edited this page Oct 10, 2024 · 11 revisions

The following functions work on the $.model global variable.

Table of contents


.create()

Create a new model:

var newModel = $.model.create("Test Model");
newModel.setAsCurrent(); // Set it to be the current model ("model")

.getLoadedModels()

Returns a list of models that are loaded in the Models Tree. Does not apply when used from the Command Line.

$.model.getLoadedModels()

Example:

var loadedModelsList = $.model.getLoadedModels();

.isAllowedRelationship()

Return true if a relationship type is allowed between two concepts

$.model.isAllowedRelationship(relationship-type, source-concept-type, target-concept-type)

Example:

var isAllowed = $.model.isAllowedRelationship("assignment-relationship", "business-actor", "business-role")

.isModelLoaded()

Return true if a given model is loaded in the Models Tree. Does not apply when used from the Command Line.

$.model.isModelLoaded(model)

Example:

var model = ...; // A model reference
var loadedinUI = $.model.isModelLoaded(model)

.load()

Load a model from file:

var myModel = $.model.load("/path/test.archimate");
myModel.setAsCurrent(); // Set it to be the current model ("model")
model.openInUI(); // Open it in the UI (Models Tree)

.renderViewAsBase64()

Get the image data encoded as Base64 from a View.

$.model.renderViewAsBase64(view, format, options...)

view - reference to a view
format - one of "PNG", "BMP", "JPG" or "GIF"
options:

  • scale - integer value of 1 to 4
  • margin - integer value of pixels

Examples:

var view = ...; // A view reference
var bytes = $.model.renderViewAsBase64(view, "PNG"); // Get bytes
// Embed in a HTML string
var html = "<html><body><p>" + view.name + "</p>" + "<img src=\"data:image/png;base64," + bytes + "\"></body></html>";
var view = ...; // A view reference
var bytes = $.model.renderViewAsBase64(view, "PNG", {scale: 1, margin: 20}); // Get bytes
// Write to file
$.fs.writeFile("path/view.png", bytes, "BASE64");

.renderViewToFile()

Render a view to file as an image:

$.model.renderViewToFile(view, filePath, format)

view - The view to render
filePath - The full file path and file name of the image
format - Image format - one of "PNG", "BMP", "JPG", "JPEG"

Render a view to file image with options:

$.model.renderViewToFile(view, filePath, format, options)

options - Image scale and margin insets. Scale can be a decimal number from 0.5 to 4. Default margin is 10.

Example:

var options = {margin: 50, scale: 2};
$.model.renderViewToFile(view, "myview.png", "PNG", options);

.renderViewToPDF()

Render a view to file image in PDF format:

$.model.renderViewToPDF(view, filePath)

view - The view to render
filePath - The full file path and file name of the PDF

Example:

$.model.renderViewToPDF(view, "myfile.pdf")

Render a view to file image in PDF format with options:

Since 1.7

$.model.renderViewToPDF(view, filePath, options)

options:

  • textAsShapes - true/false (default: true). If true, fonts are rendered as shapes.
  • embedFonts - true/false (default: false). If true, fonts are embedded.
  • textOffsetWorkaround - true/false (default: false). If true, can workaround some fonts clipping when rendered.

Each option can be omitted if required so you can set just one or two options.

Example:

var options = {textAsShapes: false, embedFonts: true, textOffsetWorkaround: true};
$.model.renderViewToPDF(view, "myfile.pdf", options);

.renderViewAsSVGString()

Render a view as an SVG String:

$.model.renderViewAsSVGString(view, setViewBox)

view - The view to render
setViewBox - true/false. If true sets the view box bounds to the bounds of the diagram.

Example:

var svgString = $.model.renderViewAsSVGString(view, true);

Render a view as an SVG String with options:

Since 1.7

$.model.renderViewAsSVGString(view, options)

options:

  • setViewBox - true/false (default: true). If true sets the view box bounds to the bounds of the diagram.
  • viewBoxBounds string of min_x min_y width height.
  • textAsShapes - true/false (default: true). If true, fonts are rendered as shapes.
  • embedFonts - true/false (default: false). If true, fonts are embedded.
  • textOffsetWorkaround - true/false (default: false). If true, can workaround some fonts clipping when rendered.

Each option can be omitted if required so you can set just one or two options.

Example:

var options = {setViewBox: false, viewBoxBounds: "0 0 1000 200", textAsShapes: false, embedFonts: true, textOffsetWorkaround: true};
var svgString = $.model.renderViewAsSVGString(view, options);

Returns the SVG image as a string.

.renderViewToSVG()

Render a view to file image in SVG format:

$.model.renderViewToSVG(view, filePath, setViewBox)

view - The view to render
filePath - The full file path and file name of the image
setViewBox - true/false. If true sets the view box bounds to the bounds of the diagram.

Render a view to file image in SVG format with options:

Since 1.7

$.model.renderViewToSVG(view, filePath, options)

options: See options for .renderViewAsSVGString()

Example:

var options = {setViewBox: false, viewBoxBounds: "0 0 1000 200", textAsShapes: false, embedFonts: true, textOffsetWorkaround: true};
$.model.renderViewToSVG(view, "test.svg", options);