Skip to content
Phil Beauvoir edited this page Oct 12, 2021 · 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")

.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)

.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")

.renderViewAsBase64()

Get the image data encoded as Base64 from a View.

.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
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 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"

.renderViewToFile(options)

Render a view to file image with options

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

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"

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

.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

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.

.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 image

.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)

.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();