Skip to content

Instantly share code, notes, and snippets.

/*
* This script attemps to import a draw.io (aka diagrams.net) diagram into an Archi model by
* empirically mapping the observable attributes of the XML elements exported from draw.io to Archimate
* elements and relationships. Please note that this mapping is fragile, because draw.io doesn't seem
* to generate the XML attributes in a very consistent way; also, we must unfortunately use element color
* as a key differentiator, to compensate for the lack of usable archimate information in the XML file.
* All of this means that minor changes in the draw.io XML format can break the mapping...
* Notes:
* -- To generate the draw.io file, export it as an *uncompressed* XML file.
* -- When running the script, make sure you have set the current model to import it in (e.g. by selecting a view in the model)
/*
* Distribute the selected (visual) elements horizontally, vertically, or both (based on response to prompt)
* Notes:
* - the center point of each element is taken as reference for the distribution
* - the overall visual order (left-to-right and top-to-bottom) of the elements is not modified
* - if a non-visual element is part of the selection, the script will crash :-(
* Author: christhearchitect, 2022
* Version: 0.1
*/
/*
* This script reads a CSV file with the following columns: Relationship type, Relationship name, Source Element name, Source Element type", Target Element name, Target Element type, {<property-name>}. Each row represents one element along with its main attributes,
* and is loaded into the current model according to these rules:
* -- if the relationship (defined by the Name/Type pair) exists in the current model, its properties are updated (subject to "overwriteAttributes" and "blankMeansDontChange" below)
* -- if not, a new relationship is created (along with its properties)
* -- the Type field is mandatory, but Name and properties can be empty
* -- if a relationship in the CSV matches several existing relationship, it is ignored
* -- the script does not create any views or visual diagram objects for the imported elements; therefore, it cannot load any visual attributes, such as style or label
*
* Author: christhearchitect
/*
* This script reads a CSV file with the following columns: Name, Type, Documentation, {<property-name>}. Each row represents one element along with its main attributes,
* and is loaded into the current model according to these rules:
* -- if the element (defined by the Name/Type pair) exists in the current model, its Documentation and properties are updated (subject to "overwriteAttributes" and "blankMeansDontChange" below)
* -- if not, a new element is created (along with its Documentation and properties)
* -- the Name field is mandatory, but Type and Documentation can be empty
* -- the script does not create any views or visual diagram objects for the imported elements; therefore, it cannot load any visual attributes, such as style or label""
*
* Author: christhearchitect
* Version: 0.2
/*
* Logs all Archi objects in the current selection to the console, in tree format.
* For each object, we list its type and name (which may be empty), plus all of its properties, if any (prefixed by "+").
* Author: christhearchitect, 2022
* Version: 0.2
*/
console.clear();
console.log("ListAllObjectsInSelection\n-------------------------\n");