You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

EA中自定义Archimate 3构造型不继承父类外观及Shape Script适配咨询

解决EA中Archimate自定义构造型特化的Shape Script颜色继承与自定义问题

1. 继承父构造型的填充色

EA的构造型特化不会自动继承父构造型的外观配置,直接用GetUserFillColor()无法获取父构造型的填充色,需要通过Shape Script结合EA API递归查找父构造型的颜色配置:

shape main {
    local var stereotypeGUID = GetElementProperty("StereotypeGUID");
    local var fillColor = GetParentStereotypeFillColor(stereotypeGUID);
    
    // 优先用父构造型颜色,无则 fallback 到当前元素默认色
    if (fillColor != -1) {
        SetFillColor(fillColor);
    } else {
        SetFillColor(GetUserFillColor());
    }
    
    // 绘制Archimate标准基础形状
    Rectangle(0,0,100,100);
}

function GetParentStereotypeFillColor(stereotypeGUID) {
    local var stereotype = Repository.GetStereotypeByGuid(stereotypeGUID);
    if (stereotype == null) return -1;
    
    // 递归查找父构造型
    if (stereotype.BaseStereotype != "") {
        local var parentStereo = Repository.GetStereotypeByName(stereotype.BaseStereotype, "Archimate3");
        if (parentStereo != null) return parentStereo.FillColor;
    }
    // 无父构造型则返回当前构造型颜色
    return stereotype.FillColor;
}

注意:需要在构造型编辑界面勾选「Enable Scripting」以启用EA API访问。

2. 为单个对象设置自定义灰色(标记超范围)

要在固定构造型颜色的基础上给单个对象改色,可通过元素标记值做条件判断:

  1. 给需要标记的元素添加标记值IsOutOfScope,值设为True
  2. 在Shape Script中加入判断逻辑:
shape main {
    local var isOutOfScope = GetElementProperty("IsOutOfScope") == "True";
    local var fillColor = GetParentStereotypeFillColor(GetElementProperty("StereotypeGUID"));
    
    // 超范围元素强制设为灰色
    if (isOutOfScope) {
        fillColor = RGB(192,192,192);
    }
    
    SetFillColor(fillColor);
    Rectangle(0,0,100,100);
}

3. 判断GetUserFillColor()返回值是否为灰色

EA中颜色以32位整数存储(格式为0xRRGGBB),判断灰色只需验证RGB分量是否近似相等:

function IsGray(color) {
    local var r = (color >> 16) & 0xFF;
    local var g = (color >> 8) & 0xFF;
    local var b = color & 0xFF;
    // 允许±2的误差,兼容EA颜色精度问题
    return (Abs(r - g) <= 2) && (Abs(g - b) <= 2);
}

调用示例:

local var currentColor = GetUserFillColor();
if (IsGray(currentColor)) {
    // 执行灰色对应的逻辑
}

内容的提问来源于stack exchange,提问作者Rik van der Schalie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 22:35:05