jArchi Collection - archimatetool/archi-scripting-plugin GitHub Wiki

[!Note] Some script snippets assume that you run them on Archisurance.archimate. In this documentation, "object" is used for any type of information (ArchiMate concept or view, but also Canvas, Folders...).

Table of contents

Traversing Navigation Filtering Attributes & Properties Model Utils
.find() .rels() .filter() .attr() .each()
.children() .inRels() .not() .prop() .clone()
.parent() .outRels() .has() .removeProp() .first()
.parents() .ends() .add() .get()
.viewRefs() .sourceEnds() .size()
.objectRefs() .targetEnds() .is()

jArchi Collection

Many methods (functions) in jArchi operate on a collection of objects rather than a single object. These collections of objects can be created from a Selector or by wrapping an object in $(). For example if you want to call rels() on a single object you would call it like this - $(object).rels().

Selectors

$(), jArchi()

This is the main selector method for jArchi. It returns an actionable collection of objects.

$(selector) // => collection
$(collection) // => self

Note that you can easily wrap an object into a collection, which makes it possible to use collection-only methods on single objects.

$(object) // => collection containing passed object

Name Selector (".name")

Select all objects with the given name.

$(".Phone") // => collection containing all objects having the name 'Phone'

Object Selector ("type")

Select all objects with the given type (see table below).

$("business-object") // => collection containing all Business Objects
Strategy Business Application Technology Physical
resource business-actor application-component node equipment
capability business-role application-collaboration device facility
course-of-action business-collaboration application-interface system-software distribution-network
value-stream business-interface application-function technology-collaboration material
business-process application-process technology-interface
business-function application-interaction path
business-interaction application-event communication-network
business-event application-service technology-function
business-service data-object technology-process
business-object technology-interaction
contract technology-event
representation technology-service
product artifact
Motivation Implementation & Migration Other Relationships Other Visual Objects Views
stakeholder work-package location composition-relationship diagram-model-note archimate-diagram-model
driver deliverable grouping aggregation-relationship diagram-model-group sketch-model
assessment implementation-even junction assignment-relationship diagram-model-connection canvas-model
goal plateau realization-relationship diagram-model-image
outcome gap serving-relationship diagram-model-reference
principle access-relationship sketch-model-sticky
requirement influence-relationship sketch-model-actor
constraint triggering-relationship canvas-model-block
meaning flow-relationship canvas-model-sticky
value specialization-relationship canvas-model-image
association-relationship

ID Selector ("#id")

Select a single element with the given id.

$("#477") // => in Archisurance.archimate, collection containing 'Maintaining Customer Relations' Business Function
$("#id-1b40f79345454fe9757d10412984c1284") // => collection containing the object with this Id

All Selector ("*")

Select all objects.

$("*") // => in Archisurance.archimate, collection containing 313 objects

Concepts Selector ("concept")

Select all ArchiMate concepts.

$("concept") // => collection

Elements Selector ("element")

Select all ArchiMate elements.

$("element") // => collection

Relationships Selector ("relationship")

Select all ArchiMate relationships.

$("relationship") // => collection

Views Selector ("view")

Select all views (ArchiMate, Sketch, Canvas).

$("view") // => collection

Folders Selector ("folder")

Select all folders.

$("folder") // => collection

Methods

These methods are available once you create a collection with $(selector) or $(object).

Traversing

These methods will 'traverse' the model structure which is made of folders and views. All of them return a new collection and don't mutate the original one.

.find()

Get the descendants of each object in the set of matched objects, optionally filtered by a selector.

collection.find() // => collection of all descendants
collection.find(selector) // => collection of descendants that match the selector
$(object).find() // => collection of all descendants of a single object

.children()

Get the children of each object in the set of matched objects, optionally filtered by a selector.

collection.children() // => collection of all children
collection.children(selector) // => collection of children that match the selector
$(object).children() // => collection of children of a single object

.parent()

Get the parent of each object in the set of matched objects, optionally filtered by a selector.

collection.parent() // => collection of parents
collection.parent(selector) // => collection of parents that match the selector
$(object).parent() // => collection of parents of a single object

.parents()

Get the ancestors of each object in the set of matched objects, optionally filtered by a selector.

collection.parents() // => collection of ancestors
collection.parents(selector) // => collection of ancestors that match the selector
$(object).parents() // => collection of ancestors of a single object

.viewRefs()

Get the views in which each object in collection is referenced, optionally filtered by a selector.

collection.viewRefs() // => collection of views
collection.viewRefs(selector) // => collection of views that match the selector
$(object).viewRefs() // => collection of views of a single object

.objectRefs()

Get the visual objects that reference each object in collection, optionally filtered by a selector.

collection.objectRefs() // => collection of (visual) objects
collection.objectRefs(selector) // => collection of (visual) objects that match the selector
$(object).objectRefs() // => collection of (visual) objects of a single object

Navigation

These methods will 'navigate' the model through relationships. All of them return a new collection and don't mutate the original one.

.rels()

Get the relationships that start or end at each concept in the set of matched objects, optionally filtered by a selector.

collection.rels() // => collection of relationships
collection.rels(selector) // => collection of relationships that match the selector
$(object).rels() // => collection of relationships of a single object

.inRels()

Get the (incoming) relationships that end at each concept in the set of matched objects, optionally filtered by a selector.

collection.inRels() // => collection of relationships
collection.inRels(selector) // => collection of relationships that match the selector
$(object).inRels() // => collection of relationships of a single object

.outRels()

Get the (outgoing) relationships that start at each concept in the set of matched objects, optionally filtered by a selector.

collection.outRels() // => collection of relationships
collection.outRels(selector) // => collection of relationships that match the selector
$(object).outRels() // => collection of relationships of a single object

.ends()

Get the concepts that are the targets or the sources of each relationship in the set of matched objects, optionally filtered by a selector.

collection.ends() // => collection of concepts
collection.ends(selector) // => collection of concepts that match the selector
$(object).ends() // => collection of concepts of a single object

.sourceEnds()

Get the concepts that are the sources of each relationship in the set of matched objects, optionally filtered by a selector.

collection.sourceEnds() // => collection of concepts
collection.sourceEnds(selector) // => collection of concepts that match the selector
$(object).sourceEnds() // => collection of concepts of a single object

.targetEnds()

Get the concepts that are the targets of each relationship in the set of matched objects, optionally filtered by a selector.

collection.targetEnds() // => collection of concepts
collection.targetEnds(selector) // => collection of concepts that match the selector
$(object).targetEnds() // => collection of concepts of a single object

Filtering

These methods allow to add to, or remove objects from the collection (which is mutated).

.filter()

Reduce the set of matched elements to those that match the selector or pass the function's test.

collection.filter(selector) // => collection of objects that match the selector
collection.filter(function(object) {return someBoolean}) // collection of objects that pass the test
$(object).filter(selector) // => collection of objects that match the selector
$(object).filter(function(object) {return someBoolean}) // collection of objects that pass the test

.not()

Remove elements from the set of matched elements. Objects to remove can come from another collection of be determined through a selector.

collection.not(selector) // => collection of concepts that don't match the selector
collection.not(otherCollection) // => collection of concepts that are not in the passed collection
$(object).not(selector) // => collection of concepts that don't match the selector
$(object).not(otherCollection) // => collection of concepts that are not in the passed collection

.has()

Reduce the set of matched elements to those that have a descendant that matches the selector.

collection.has(selector) // => collection of concepts
$(object).has(selector) // => collection of concepts

.add()

Create a new jArchi Collection with objects added to the set of matched objects. Added objects can come from another collection of be determined through a selector.

collection.add(selector) //=> collection
collection.add(otherCollection) // => collection
$(object).add(otherCollection) // => collection

Attributes & Properties

.attr()

Get the value of an attribute for the first object in the set of matched object or set one or more attributes for every matched object.

These attr methods correspond to getters and setters of the same name, so name = $(object).attr("name") is the equivalent of name = object.name.

collection.attr(attrName) // => AttributeValue
collection.attr(attrName, attrValue) // => updated collection
$(object).attr(attrName) // => AttributeValue
$(object).attr(attrName, attrValue) // => updated collection

An attribute is applicable for the type of object it is used for. For example, junction-type can only used on a Junction concept.

To determine which object an attr applies to refer to the wiki entry for the corresponding getter or setter. For example, the attribute fillColor would correspond to getFillColor() and setFillColor(value) for a diagram object.

An example to set and get the name of a single object:

// The following is the equivalent of:
// object.name = "New Name"
// name = object.name
$(object).attr("name", "New Name"); // Set name
name = $(object).attr("name"); // Get name

List of possible attrName keys (case-sensitive):

access-type
association-directed
borderType
bounds
concept (get only)
connectionRouter
deriveLineColor
id (get only)
influence-strength
figureType
fillColor
fontColor
fontName
fontSize
fontStyle
gradient
iconColor
image
imageSource
imagePosition
index
junction-type
documentation
label-expression
label-value (get only)
labelVisible
lineColor
lineStyle
lineWidth
opacity
outlineOpacity
name
purpose
relativeBendpoints (get only)
showIcon
source (get only for diagram connections)
specialization
style
target (get only for diagram connections)
text
textAlignment
textPosition
type (get only)
view (get only)
viewpoint

.prop()

If no arguments are provided, return the list of properties' key for the first object in the collection.

Return a property value of the first object in the collection when just property is supplied. If multiple properties exist with the same key, then return only the first one (duplicate=false, which is the default) or an array with all values (duplicate=true)

Sets a property for every objects when property and value are supplied. Property is updated if it already exists (duplicate=false, which is the default) or added anyway (duplicate=true).

collection.prop() //=> properties' key for the first object
collection.prop(propName) // => property value (first one if multiple entries)
collection.prop(propName, false) // => property value (first one if multiple entries)
collection.prop(propName, true) // => property value (array if multiple entries)
collection.prop(propName, propValue) // => updated collection with property added (if it did not exist) or updated (if it existed)
collection.prop(propName, propValue, false) // => updated collection with property added (if it not existed) or updated (if it existed)
collection.prop(propName, propValue, true) // => updated collection with property added (even if it existed)

The above examples can be applied to a single object wrapped in a $() collection:

$(object).prop()
$(object).prop(propName)
$(object).prop(propName, false)
$(object).prop(propName, true)
$(object).prop(propName, propValue)
$(object).prop(propName, propValue, false)
$(object).prop(propName, propValue, true)

.removeProp()

Removes property from collection objects.

collection.removeProp(propName) // => all instances of propName are removed
collection.removeProp(propName, propValue) // => properties are removed if value matches propValue
$(object).removeProp(propName) // => all instances of propName are removed
$(object).removeProp(propName, propValue) // => properties are removed if value matches propValue

Model

Utils

.each()

Iterate over a collection, executing a function for each object. The function to execute will receive the current object as first argument.

collection.each(function(obj) {console.log(obj.id)}) // => print ids of all objects
$(object).each(function(obj) {console.log(obj.id)})

.clone()

Create a copy of the set of matched objects. Objects themselves are not copied, only the collection is.

collection.clone() // => a copy of the collection
$(object).clone()

.first()

Reduce the set of matched objects to the first in the set.

collection.first() // => first object

.get()

Retrieve one of the objects matched by the collection.

collection.get(n) // => return object at index 'n' from the collection

.size()

Return the number of objects in the collection.

$('business-object').size() // => Return the number of Business Object in the current model

.is()

Check the current matched set of object against a selector and return true if at least one of these objects matches the given arguments.

$(selection).is('business-object') // => Return true is there is at least one Business Object in the selection, false otherwise