JArchi Scripting by thomasrohde/marketplace
npx skills add https://github.com/thomasrohde/marketplace --skill 'JArchi Scripting'为开源 ArchiMate 建模工具 Archi 创建 JavaScript 脚本(.ajs 文件)。JArchi 支持以编程方式访问 ArchiMate 模型,实现自动化、报告和批量操作。
JArchi 脚本使用 JavaScript 并采用类似 jQuery 的 API。脚本使用 .ajs 扩展名,并通过全局变量访问模型:
// 所有脚本中可用的全局变量
model // 当前模型(必须已选中或加载)
selection // 用户界面中当前选中的对象
$(selector) // 类似 jQuery 的选择器函数(jArchi() 的别名)
使用类似 CSS 的选择器查询模型对象:
// 按类型(连字符格式的 ArchiMate 类型)
$("business-actor") // 所有业务执行者
$("application-component") // 所有应用组件
$("serving-relationship") // 所有服务关系
// 按名称
$(".Customer Portal") // 名为 "Customer Portal" 的对象
// 按 ID
$("#abc-123") // 具有特定 ID 的对象
// 特殊选择器
$("element") // 所有 ArchiMate 元素
$("relationship") // 所有关系
$("view") // 所有视图(ArchiMate、画布、草图)
$("folder") // 所有文件夹
$("concept") // 所有元素和关系
$("*") // 所有对象
集合支持链式调用和迭代:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
// 遍历
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) { /* 处理 obj */ });
collection.size() // 对象数量
// 属性
collection.attr("name") // 获取属性
collection.attr("name", "New Name") // 设置属性
collection.prop("key") // 获取属性
collection.prop("key", "value") // 设置属性
// 元素
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");
设置图表对象的外观:
// 颜色(十六进制格式)
diagramObject.fillColor = "#dae8fc";
diagramObject.lineColor = "#6c8ebf";
diagramObject.fontColor = "#333333";
// 字体
diagramObject.fontSize = 12;
diagramObject.fontStyle = "bold"; // normal, bold, italic, bolditalic
// 位置和大小
diagramObject.bounds = {x: 100, y: 100, width: 120, height: 60};
// 其他
diagramObject.opacity = 200; // 0-255
diagramObject.labelExpression = "${name}\n${type}";
// 控制台输出
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"});
// 写入文件
$.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__ // 用户的脚本目录
// 渲染到文件
$.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");
使用 Archi 命令行界面无头运行脚本。
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"
--loadModel "path/model.archimate" 加载现有模型
--createEmptyModel 创建空白模型
--script.runScript "script.ajs" 运行 jArchi 脚本
--saveModel "path/output.archimate" 脚本运行后保存模型
--csv.export "path/output" 导出到 CSV
--html.createReport "path/output" 生成 HTML 报告
--xmlexchange.export "path/output.xml" 导出到 Open Exchange XML
向脚本传递自定义参数:
& Archi.exe -application com.archimatetool.commandline.app -consoleLog -nosplash `
--loadModel "model.archimate" `
--script.runScript "script.ajs" `
--myArg "value" --anotherArg "value2"
在脚本中访问:
var args = $.process.argv;
args.forEach(function(arg) {
console.log(arg);
});
适用于没有显示器的服务器:
xvfb-run Archi -application com.archimatetool.commandline.app \
-consoleLog -nosplash --loadModel "model.archimate" \
--script.runScript "script.ajs"
| 层级 | 类型 |
|---|---|
| 战略 | resource, capability, course-of-action, value-stream |
| 业务 | business-actor, business-role, business-process, business-function, business-service, business-object, contract, product |
| 应用 | application-component, application-function, application-service, application-interface, data-object |
| 技术 | node, device, system-software, technology-service, artifact, communication-network, path |
| 物理 | equipment, facility, distribution-network, material |
| 动机 | stakeholder, driver, goal, requirement, constraint, principle, outcome |
| 实施 | work-package, deliverable, plateau, gap |
| 其他 | location, grouping, junction |
composition-relationship, aggregation-relationship, assignment-relationship, realization-relationship, serving-relationship, access-relationship, influence-relationship, triggering-relationship, flow-relationship, specialization-relationship, association-relationship
在操作前检查模型是否已设置:
if (!model.isSet()) { console.error("No model selected"); exit(); }
创建元素时使用有意义的名称
批量操作 - 收集更改,最后统一应用
使用 try/catch 优雅地处理错误
为长时间运行的脚本记录进度
使用文件夹来组织创建的元素
详细 API 文档请查阅:
references/api-elements.md - 元素类型、创建、属性references/api-collections.md - 选择器、遍历、过滤references/api-views.md - 视图、视觉对象、样式references/api-model.md - 模型操作、加载、保存references/api-utilities.md - 控制台、对话框、文件 I/Oreferences/cli-reference.md - 完整的 CLI 选项和自动化examples/ 目录中的工作示例:
query-elements.ajs - 查询和报告模型元素create-view.ajs - 创建包含元素和关系的视图export-report.ajs - 将模型数据导出到 CSVbatch-update.ajs - 批量更新元素属性cli-automation.ps1 - PowerShell 自动化脚本cli-automation.sh - Bash 自动化脚本每周安装次数
–
代码仓库
GitHub 星标数
1
首次出现时间
–
安全审计
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.
JArchi scripts use JavaScript with a jQuery-like API. Scripts have .ajs extension and access the model through global variables:
// Global variables available in all scripts
model // The current model (must be selected or loaded)
selection // Currently selected objects in UI
$(selector) // jQuery-like selector function (alias for jArchi())
Query model objects using CSS-like selectors:
// By type (kebab-case ArchiMate types)
$("business-actor") // All business actors
$("application-component") // All application components
$("serving-relationship") // All serving relationships
// By name
$(".Customer Portal") // Objects named "Customer Portal"
// By ID
$("#abc-123") // Object with specific ID
// Special selectors
$("element") // All ArchiMate elements
$("relationship") // All relationships
$("view") // All views (ArchiMate, Canvas, Sketch)
$("folder") // All folders
$("concept") // All elements and relationships
$("*") // Everything
Collections support chaining and iteration:
// Traversal
collection.children() // Direct children
collection.parent() // Parent folder/container
collection.find(selector) // Descendants matching selector
// Navigation (relationships)
collection.rels() // All connected relationships
collection.inRels() // Incoming relationships
collection.outRels() // Outgoing relationships
collection.sourceEnds() // Source concepts of relationships
collection.targetEnds() // Target concepts of relationships
// Filtering
collection.filter(selector) // Keep matching objects
collection.not(selector) // Exclude matching objects
collection.first() // First object only
// Iteration
collection.each(function(obj) { /* process obj */ });
collection.size() // Count of objects
// Attributes
collection.attr("name") // Get attribute
collection.attr("name", "New Name") // Set attribute
collection.prop("key") // Get property
collection.prop("key", "value") // Set property
// Elements
var actor = model.createElement("business-actor", "Customer");
var component = model.createElement("application-component", "API Gateway");
// Relationships
var rel = model.createRelationship("serving-relationship", "", component, actor);
// Views
var view = model.createArchimateView("Overview");
// Add elements to view
var obj1 = view.add(actor, 100, 100, 120, 60);
var obj2 = view.add(component, 300, 100, 120, 60);
// Add relationship to view
view.add(rel, obj1, obj2);
// Folders
var folder = $("folder.Business").first();
var subfolder = folder.createFolder("Processes");
Set appearance of diagram objects:
// Colors (hex format)
diagramObject.fillColor = "#dae8fc";
diagramObject.lineColor = "#6c8ebf";
diagramObject.fontColor = "#333333";
// Font
diagramObject.fontSize = 12;
diagramObject.fontStyle = "bold"; // normal, bold, italic, bolditalic
// Position and size
diagramObject.bounds = {x: 100, y: 100, width: 120, height: 60};
// Other
diagramObject.opacity = 200; // 0-255
diagramObject.labelExpression = "${name}\n${type}";
// Console output
console.log("Message");
console.error("Error message");
console.clear();
console.show();
// User dialogs
window.alert("Information");
var confirmed = window.confirm("Proceed?");
var input = window.prompt("Enter name:", "Default");
var selection = window.promptSelection("Choose:", ["Option 1", "Option 2"]);
// File dialogs
var filePath = window.promptOpenFile({title: "Open", filterExtensions: ["*.csv"]});
var savePath = window.promptSaveFile({title: "Save", filterExtensions: ["*.csv"]});
var dirPath = window.promptOpenDirectory({title: "Select Folder"});
// Write file
$.fs.writeFile("path/to/file.csv", content, "UTF8");
$.fs.writeFile("path/to/file.bin", base64Data, "BASE64");
// Include other scripts
load(__DIR__ + "lib/helpers.js");
// Special variables
__DIR__ // Directory containing current script
__FILE__ // Path to current script
__SCRIPTS_DIR__ // User's scripts directory
// Render to file
$.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);
// Render to string/bytes
var svgString = $.model.renderViewAsSVGString(view, true);
var base64 = $.model.renderViewAsBase64(view, "PNG");
Run scripts headlessly using Archi Command Line Interface.
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"
--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
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);
});
For servers without display:
xvfb-run Archi -application com.archimatetool.commandline.app \
-consoleLog -nosplash --loadModel "model.archimate" \
--script.runScript "script.ajs"
| Layer | Types |
|---|---|
| Strategy | resource, capability, course-of-action, value-stream |
| Business | business-actor, business-role, business-process, business-function, business-service, , , |
composition-relationship, aggregation-relationship, assignment-relationship, realization-relationship, serving-relationship, access-relationship, influence-relationship, triggering-relationship, flow-relationship, specialization-relationship, association-relationship
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
For detailed API documentation, consult:
references/api-elements.md - Element types, creation, propertiesreferences/api-collections.md - Selectors, traversal, filteringreferences/api-views.md - Views, visual objects, stylingreferences/api-model.md - Model operations, loading, savingreferences/api-utilities.md - Console, dialogs, file I/Oreferences/cli-reference.md - Complete CLI options and automationWorking examples in examples/:
query-elements.ajs - Query and report on model elementscreate-view.ajs - Create view with elements and relationshipsexport-report.ajs - Export model data to CSVbatch-update.ajs - Batch update element propertiescli-automation.ps1 - PowerShell automation scriptcli-automation.sh - Bash automation scriptWeekly Installs
–
Repository
GitHub Stars
1
First Seen
–
Security Audits
通过 LiteLLM 代理让 Claude Code 对接 GitHub Copilot 运行 | 高级变通方案指南
31,600 周安装
business-objectcontractproduct| 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 |