Skip to content

Instantly share code, notes, and snippets.

@jbsarrodie
jbsarrodie / Sync Model from CSV.ajs
Last active May 10, 2021
#jArchi scripts to sync (some) model concepts from one or more CSV files
View Sync Model from CSV.ajs
// Sync Model from CSV.ajs
//
// Requires jArchi - https://www.archimatetool.com/blog/2018/07/02/jarchi/
//
// This script allows easy integration of data coming from other systems through CSV files.
// Each CSV file is described through a configuration object that you can later load and sync.
// Most of the mapping informations (Id, Name, Documentation, Properties...) can be expressed through
// the name of a column from the CSV file or through a function (which allows more advanced computation).
//
// Dataset used as example comes from https://datahub.io/core/country-codes
@jbsarrodie
jbsarrodie / Resize objects in selected view.ajs
Created Mar 2, 2020
#jArchi script to resize visual objects in the selected view
View Resize objects in selected view.ajs
// Resize objects in selected view
//
// Requires jArchi - https://www.archimatetool.com/blog/2018/07/02/jarchi/
//
// This script resizes visual objects in the selected view
//
// (c) 2020 Jean-Baptiste Sarrodie
var factor = window.prompt("Resize factor for objects?", 2);
if (!factor) {
@jbsarrodie
jbsarrodie / Merge multiple concepts (and delete others).ajs
Last active Aug 27, 2020
#jArchi script to merge multiple concepts (and delete others)
View Merge multiple concepts (and delete others).ajs
// Merge multiple concepts (and delete others)
//
// Requires jArchi - https://www.archimatetool.com/blog/2018/07/02/jarchi/
//
// This script merges multiple concepts (and delete others)
//
// Version 1.1 (2020/01/20) Add an option to keep only the content of the "target" concept
// Version 1.0 (2019/11/12) First version published
//
// Known limitation: works only on elements, not relationships
@jbsarrodie
jbsarrodie / Delete unused elements and relationships.ajs
Created Mar 2, 2020
#jArchi scripts to delete any element (or relationship) not used in at least one view
View Delete unused elements and relationships.ajs
// Delete unused elements and relationships
//
// Requires jArchi - https://www.archimatetool.com/blog/2018/07/02/jarchi/
//
// This script will delete any element or relationship not used in at least one view
//
// (c) 2020 Jean-Baptiste Sarrodie
var response = window.confirm("This script will delete any element or relationship not used in at least one view. Continue?");
@jbsarrodie
jbsarrodie / ConvertConcept.lib.js
Last active Apr 10, 2021
#jArchi script to change concepts' type (and optionally convert no more valid relationships to association)
View ConvertConcept.lib.js
function convert(selection, convertToType) {
var relaxed = window.confirm('By default, selected concepts are converted, and relationships involving them that would no more be valid are converted to associations. Click Ok for this behavior or Cancel if you want a "strict" mode where relationships are not changed.');
$(selection).each(function(o) {
$(concept(o)).outRels().each(function(r) {
if (! $.model.isAllowedRelationship(r.type, convertToType, r.target.type)) {
checkAndConvertRelationship(r, relaxed);
}
});
$(concept(o)).inRels().each(function(r) {
@jbsarrodie
jbsarrodie / RemoveBentpoints.ajs
Created Sep 14, 2018
#jArchi script to remove bendpoints on selected relationships
View RemoveBentpoints.ajs
// RemoveBentpoints
//
// Requires jArchi - https://www.archimatetool.com/blog/2018/07/02/jarchi/
//
// This script takes a selection of visual objects as input, filter it to keep only relationships and remove all their bendpoints
//
// (c) 2018 Jean-Baptiste Sarrodie
$(selection).filter("relationship").filter(function(o) {return o.view}).each(function(o) {
var view = o.view;
@jbsarrodie
jbsarrodie / RemoveProperty.ajs
Created Sep 6, 2018
#jArchi script to delete a property on a selection of objects
View RemoveProperty.ajs
var propName = window.prompt("Which property do you want to remove (leave empty to cancel)?", "");
if (propName) {
$(selection).removeProp(propName);
}
@jbsarrodie
jbsarrodie / AddOrUpdateProperty.ajs
Created Sep 6, 2018
#jArchi script to add or update properties on a selection of objects
View AddOrUpdateProperty.ajs
var propName = window.prompt("Which property do you want to add or update (leave empty to cancel)?", "");
if (propName) {
var propValue = window.prompt("Which value do you want to set for '"+propName+"' (leave empty to cancel)?", "");
if (propValue) {
$(selection).prop(propName, propValue);
}
}
@jbsarrodie
jbsarrodie / AddUnshownRelationship.ajs
Last active Aug 21, 2019
#jArchi script to add all possible relationships to a view
View AddUnshownRelationship.ajs
// Find DiagramComponents for a given element in a given view
var getDiagramComponents = function(v, e) {
return $(v).find("concept").filter(function(o) {
return o.concept.id == e.id;
});
}
// Checks if a view contains a visual connection from src and tgt visual objects
var contains = function(r, src, tgt) {
found = false;