【问题标题】:Sparx Enterprise Architect scripting: Enumerate Package ElementsSparx Enterprise Architect 脚本:枚举包元素
【发布时间】:2015-11-11 11:33:27
【问题描述】:

使用 JScript,我想枚举特定包下的元素。

我收到了#OBJECTID#,这是包元素的 ID。

我用它来获取元素。

但是当我计算元素时,它们总是 0。

我错过了什么步骤?

function devTest()
{
    var package = Repository.GetPackageByGuid("{2255D8C8-F1BB-4069-BDAF-8B303D108C62}");

    // When testing use the Element associate to the Package, not 
    // the Package ID itself (Pretty sure that that 
    // this equivalent to the #OBJECTID# macro).
    var packageElementId = package.Element.ElementID; //NOT: package.PackageID;

    var packageElement = Repository.GetElementByID(packageElementId);

    var elementCollection = packageElement.Elements();
    Session.Output("Element Count: " + elementCollection.Count());

    //ALWAYS ZERO. Not showing Classes and Attributes that are nested under the Package.
}

感谢您的帮助!

【问题讨论】:

  • 我建议搜索/交叉发布到 Sparx 论坛。内部代码猴子阅读并发布到那里,据我所知,他们在这个网站上远不及多产。

标签: enterprise-architect


【解决方案1】:

原来我需要 GetPackageByGuid 方法来返回与元素关联的包。看来 Package 的 Elements 集合是正确使用的集合。去图...

//Get back to the package that is related to the Element before you count Elements:
var package = Repository.GetPackageByGuid(packageElement.ElementGUID);
var elementCollection = package.Elements;
Session.Output("Element Count: " + elementCollection.Count());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-10
    • 2015-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多