| name | JArchi Scripting |
| description | This skill should be used when the user asks to "create a jArchi script", "write an Archi script", "automate ArchiMate", "export from Archi", "query ArchiMate elements", "create ArchiMate views", "run Archi headlessly", "Archi CLI", "batch process ArchiMate model", or mentions "jArchi", ".ajs script", "Archi automation", or ArchiMate scripting. Provides comprehensive jArchi API knowledge and CLI automation support. |
| version | 1.0.0 |
JArchi Scripting
Create JavaScript scripts (.ajs files) for Archi, the open-source ArchiMate modeling tool. JArchi enables programmatic access to ArchiMate models for automation, reporting, and batch operations.
Core Concepts
Script Basics
JArchi scripts use JavaScript with a jQuery-like API. Scripts have .ajs extension and access the model through global variables:
model
selection
$(selector)
Selectors
Query model objects using CSS-like selectors:
$("business-actor")
$("application-component")
$("serving-relationship")
$(".Customer Portal")
$("#abc-123")
$("element")
$("relationship")
$("view")
$("folder")
$("concept")
$("*")
Collection Methods
Collections support chaining and iteration:
collection.children()
collection.parent()
collection.find(selector)
collection.rels()
collection.inRels()
collection.outRels()
collection.sourceEnds()
collection.targetEnds()
collection.filter(selector)
collection.not(selector)
collection.first()
collection.each(function(obj) { });
collection.size()
collection.attr("name")
collection.attr("name", "New Name")
collection.prop("key")
collection.prop("key", "value")
Creating Model Content
var actor = model.createElement("business-actor", "Customer");
var component = model.createElement("application-component", "API Gateway");
var rel = model.createRelationship("serving-relationship", "", component, actor);
var view = model.createArchimateView("Overview");
var obj1 = view.add(actor, 100, 100, 120, 60);
var obj2 = view.add(component, 300, 100, 120, 60);
view.add(rel, obj1, obj2);
var folder = $("folder.Business").first();
var subfolder = folder.createFolder("Processes");
Visual Styling
Set appearance of diagram objects:
diagramObject.fillColor = "#dae8fc";
diagramObject.lineColor = "#6c8ebf";
diagramObject.fontColor = "#333333";
diagramObject.fontSize = 12;
diagramObject.fontStyle = "bold";
diagramObject.bounds = {x: 100, y: 100, width: 120, height: 60};
diagramObject.opacity = 200;
diagramObject.labelExpression = "${name}\n${type}";
Console and Dialogs
console.log("Message");
console.error("Error message");
console.clear();
console.show();
window.alert("Information");
var confirmed = window.confirm("Proceed?");
var input = window.prompt("Enter name:", "Default");
var selection = window.promptSelection("Choose:", ["Option 1", "Option 2"]);
var filePath = window.promptOpenFile({title: "Open", filterExtensions: ["*.csv"]});
var savePath = window.promptSaveFile({title: "Save", filterExtensions: ["*.csv"]});
var dirPath = window.promptOpenDirectory({title: "Select Folder"});
File Operations
$.fs.writeFile("path/to/file.csv", content, "UTF8");
$.fs.writeFile("path/to/file.bin", base64Data, "BASE64");
load(__DIR__ + "lib/helpers.js");
__DIR__
__FILE__
__SCRIPTS_DIR__
Exporting Views
$.model.renderViewToFile(view, "diagram.png", "PNG");
$.model.renderViewToFile(view, "diagram.png", "PNG", {scale: 2, margin: 20});
$.model.renderViewToPDF(view, "diagram.pdf");
$.model.renderViewToSVG(view, "diagram.svg", true);
var svgString = $.model.renderViewAsSVGString(view, true);
var base64 = $.model.renderViewAsBase64(view, "PNG");
CLI Execution
Run scripts headlessly using Archi Command Line Interface.
Basic Syntax
Windows (PowerShell):
& "C:\Program Files\Archi\Archi.exe" -application com.archimatetool.commandline.app `
-consoleLog -nosplash `
--loadModel "model.archimate" `
--script.runScript "script.ajs"
Windows (CMD):
"C:\Program Files\Archi\Archi.exe" -application com.archimatetool.commandline.app ^
-consoleLog -nosplash ^
--loadModel "model.archimate" ^
--script.runScript "script.ajs"
Linux/macOS:
Archi -application com.archimatetool.commandline.app \
-consoleLog -nosplash \
--loadModel "model.archimate" \
--script.runScript "script.ajs"
Common CLI Options
--loadModel "path/model.archimate" Load existing model
--createEmptyModel Create blank model
--script.runScript "script.ajs" Run jArchi script
--saveModel "path/output.archimate" Save model after script
--csv.export "path/output" Export to CSV
--html.createReport "path/output" Generate HTML report
--xmlexchange.export "path/output.xml" Export to Open Exchange XML
Script Arguments
Pass custom arguments to scripts:
& Archi.exe -application com.archimatetool.commandline.app -consoleLog -nosplash `
--loadModel "model.archimate" `
--script.runScript "script.ajs" `
--myArg "value" --anotherArg "value2"
Access in script:
var args = $.process.argv;
args.forEach(function(arg) {
console.log(arg);
});
Linux Headless Mode
For servers without display:
xvfb-run Archi -application com.archimatetool.commandline.app \
-consoleLog -nosplash --loadModel "model.archimate" \
--script.runScript "script.ajs"
ArchiMate Types Reference
Element Types
| Layer | Types |
|---|
| Strategy | resource, capability, course-of-action, value-stream |
| Business | business-actor, business-role, business-process, business-function, business-service, business-object, contract, product |
| Application | application-component, application-function, application-service, application-interface, data-object |
| Technology | node, device, system-software, technology-service, artifact, communication-network, path |
| Physical | equipment, facility, distribution-network, material |
| Motivation | stakeholder, driver, goal, requirement, constraint, principle, outcome |
| Implementation | work-package, deliverable, plateau, gap |
| Other | location, grouping, junction |
Relationship Types
composition-relationship, aggregation-relationship, assignment-relationship, realization-relationship, serving-relationship, access-relationship, influence-relationship, triggering-relationship, flow-relationship, specialization-relationship, association-relationship
Best Practices
-
Check model is set before operations:
if (!model.isSet()) {
console.error("No model selected");
exit();
}
-
Use meaningful names when creating elements
-
Batch operations - collect changes, apply at end
-
Handle errors gracefully with try/catch
-
Log progress for long-running scripts
-
Use folders to organize created elements
Additional Resources
Reference Files
For detailed API documentation, consult:
references/api-elements.md - Element types, creation, properties
references/api-collections.md - Selectors, traversal, filtering
references/api-views.md - Views, visual objects, styling
references/api-model.md - Model operations, loading, saving
references/api-utilities.md - Console, dialogs, file I/O
references/cli-reference.md - Complete CLI options and automation
Example Scripts
Working examples in examples/:
query-elements.ajs - Query and report on model elements
create-view.ajs - Create view with elements and relationships
export-report.ajs - Export model data to CSV
batch-update.ajs - Batch update element properties
cli-automation.ps1 - PowerShell automation script
cli-automation.sh - Bash automation script