Skip to content
Phil Beauvoir edited this page Jun 26, 2024 · 3 revisions

Note

Attributes and methods described in this section are available on the model object

Contents

.copy()
.createArchimateView()
.createCanvasView()
.createElement()
.createImage()
.createRelationship()
.createSketchView()
.createSpecialization()
.findSpecialization()
.getPath()
.merge()
.openInUI()
.purpose
.save()
.setAsCurrent()
.specializations


.copy()

Returns a new reference to the model. Example:

var modelref = model.copy(); // => Copy a reference to the current model

.createArchimateView()

Create a new ArchiMate View in the model.

Create and add a new view (to the default folder) in the model:

model.createArchimateView(name);

Create and add a new view to a given folder in the model:

model.createArchimateView(name, folder);

Examples:

var view = model.createArchimateView("New Archimate View");
var view2 = model.createArchimateView("Archimate View", myFolder);

.createCanvasView()

Create a new Canvas View in the model.

Create and add a new view (to the default folder) in the model:

model.createCanvasView(name);

Create and add a new view to a given folder in the model:

model.createCanvasView(name, folder);

Examples:

var view = model.createCanvasView("New Canvas View");
var view2 = model.createCanvasView("Canvas View", myFolder);

.createElement()

Create and add a new element to its default folder in the model.

model.createElement(element-type, name);

Create and add a new element to a given folder in the model:

model.createElement(element-type, name, folder);

Use the kebab-case type of the element and provide a name. Examples:

var actor = model.createElement("business-actor", "Oscar");
var role = model.createElement("business-role", "Cat");
var node = model.createElement("node", "Node");
var junction = model.createElement("junction", "");

.createImage()

model.createImage(filePath)

Load an image from file and store it in the model.

Returns the image object which can used to assign to a specialization or visual object. If the image is already loaded in the model, it is returned. Images are matched on content not name.

An image object has fields width and height.

filePath The full file path and file name of the image to load.

Example:

var image = model.createImage("path_to/cat.png");
console.log("Image height: " + image.height);
console.log("Image width: " + image.width);
selectedDiagramObject.image = image;

.createRelationship()

Create and add a new relationship to its default folder in the model.

model.createRelationship(relationship-type, name, source, target);

Create and add a new relationship to a given folder in the model:

model.createRelationship(relationship-type, name, source, target, folder);

Use the kebab-case type of the relationship and provide a name (can be "") and the source and target components. Example:

var actor = model.createElement("business-actor", "Oscar");
var role = model.createElement("business-role", "Cat");
var relationship = model.createRelationship("assignment-relationship", "Assigned to", actor, role);

.createSketchView()

Create a new Sketch View in the model.

Create and add a new view (to the default folder) in the model:

model.createSketchView(name);

Create and add a new view to a given folder in the model:

model.createSketchView(name, folder);

Examples:

var view = model.createSketchView("New Sketch View");
var view2 = model.createSketchView("Sketch View", myFolder);

.createSpecialization()

model.createSpecialization(name, conceptType)

model.createSpecialization(name, conceptType, image)

Create a new specialization with the given name, concept type and image. If a specialization of the same name and type already exists, an exception is thrown.

name - The name of the specialization

type - The concept type in kebab-case format.

image - An image object previously stored from model.createImage(), or from a Specialization object returned from model.getSpecializations(), or model.findSpecialization(). Can be omitted or null for no image.

Returns a Specialization object containing the fields name, conceptType, and image

Example:

// Create a new specialization with image for Business Actor called "Oscar"
var image = model.createImage("cat.png");
var specialization = model.createSpecialization("Oscar", "business-actor", image);

// Set the specialization on a concept by using its name
var businessActor = ...;
businessActor.specialization = "Oscar";

// We can get its properties
var name = specialization.name;
var type = specialization.type;
var image = specialization.image;
console.log("Image height: " + image.height);
console.log("Image width: " + image.width);

A Specialization object's properties can be set:

specialization.name = "New Name";
specialization.type = "business-object";
specialization.image = imageFromAnotherSpecialization;

If a Specialization object already exists with the given name and/or concept type the name and conceptType properties cannot be set.

A Specialization object can be deleted from the model with specialization.delete(). All concept references to the specialization are also deleted.

.findSpecialization()

model.findSpecialization(name, type)

Find and return a Specialization object in the model with the given name and type. If a matching specialization does not exist, null is returned.

Example:

var specialization = model.findSpecialization("Oscar", "business-actor";

.getPath()

Return the path to the file location of the model, or null if not saved.

var filePath = model.getPath();

.merge()

Merge another model into this model. This is the equivalent of the "Import another model into the selected model" Archi action.

model.merge(filePath, update, updateAll)
model.merge(filePath, update, updateAll, messages)

Merge the model located at filePath into this model.

filePath - path to the *.archimate model file
update - if true, update/replace target objects with source objects - sub-folders, concepts, folder structure, views
updateAll - if true update/replace model and top level folders' name, purpose, documentation and properties with source
messages - an optional empty array into which merge operation messages are stored

Example:

let messages = []; // List of messages returned by merge operation (optional)
model.merge("pathToFile/mymodel.archimate", true, true, messages);
messages.forEach(m => { // Print messages
    console.log(m);
});

model.merge(anotherModel, update, updateAll)
model.merge(anotherModel, update, updateAll, messages)

Merge another model into this model.

anotherModel - another model previously created or loaded in jArchi
update - if true, update/replace target objects with source objects - sub-folders, concepts, folder structure, views
updateAll - if true update/replace model and top level folders' name, purpose, documentation and properties with source
messages - an optional empty array into which merge operation messages are stored

Example:

let messages = []; // List of messages returned by merge operation (optional)
let thatModel = $.model.load("pathToFile/mymodel.archimate");
model.merge(thatModel, true, true, messages);
messages.forEach(m => { // Print messages
    console.log(m);
});

.openInUI()

Open the model in the UI (Models Tree).

model.openInUI();

.purpose

Get/set model's purpose (documentation).

var purpose = object.purpose;
object.purpose= 'New purpose content';

.save()

Save the model to file.

model.save(); // If the model has previously been saved with a path and file name, save the model
model.save("path/test.archimate"); // Save the model to the given path and file name

.setAsCurrent()

Set a model to the current model. The current model is referenced as the global variable model.

Example:

$.model.load("path/test.archimate").setAsCurrent(); // Load a model and set it as the current model

or:

var myModel = model.load("path/test.archimate");
myModel.setAsCurrent();

.specializations

Returns a list of all Specialization objects in the model. A Specialization object contains the fields name, conceptType, and image

Example:

model.specializations.forEach(specialization => {
    console.log(specialization.name);
    console.log(specialization.type);
    console.log(specialization.image);
});