【问题标题】:How to change the default scope of attributes from Private to Public in Enterprise Architect?如何在 Enterprise Architect 中将属性的默认范围从私有更改为公共?
【发布时间】:2013-06-07 15:15:47
【问题描述】:

有人知道如何更改 Enterprise Architect 中 UML 类属性的默认范围(我使用的是 9.2 版)吗?添加新属性时,默认设置为私有。我主要是用Enterprise Architect做数据建模,所有的属性都应该是public的。

目前,我必须手动将我添加的每个属性的范围从 Private 更改为 Public,所以如果我可以将新属性的默认范围设置为 Public,我会节省相当多的时间。

【问题讨论】:

  • 我很确定没有此选项设置。您可以尝试编写一个响应 EA_OnPostNewAttribute 广播的加载项。
  • 好的,谢谢,我将关闭问题并使用下面答案中的脚本作为解决方法。

标签: enterprise-architect


【解决方案1】:

您可以使用以下脚本将包中的所有私有属性更改为公共属性。

!INC Local Scripts.EAConstants-JScript

function main()
{
    Repository.EnsureOutputVisible( "Script" );
    Repository.ClearOutput( "Script" );

    // Get the type of element selected in the Project Browser
    var treeSelectedType = Repository.GetTreeSelectedItemType();

    switch ( treeSelectedType )
    {
        case otPackage :
        {
            // Code for when a package is selected
            var pkg as EA.Package;
            pkg = Repository.GetTreeSelectedObject();

            Session.Output("----------------------------------------");
            Session.Output("Processing... " + pkg.Name);

            for (var i = 0 ; i < pkg.Elements.Count; i++)
            {
                var element as EA.Element;
                element = pkg.Elements.GetAt(i);

                Session.Output("Analyzing : " + element.Name);

                for (var j = 0; j < element.Attributes.Count; j++)
                {
                    var attrib as EA.Attribute;
                    attrib = element.Attributes.GetAt(j);

                    if (attrib.Visibility == "Private")
                    {
                        attrib.Visibility = "Public";
                        attrib.Update();
                        Session.Output("- Changed attribute :" + attrib.Name);
                    }
                }
                element.Update();
                element.Refresh();
            }

            Session.Output("----------------------------------------");
            break;
        }

        default:
        {
            // Error message
            Session.Prompt( "This script does not support items of this type.", promptOK );
        }
    }
}

main();

TIPS:如果还需要一些私有属性,可以在属性名中添加额外的标志/字符,然后修改上面的脚本解析属性名,找到后才改为public标志并从属性名称中删除标志。

【讨论】:

  • 感谢脚本,非常有用。
猜你喜欢
  • 2019-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-09
  • 2021-07-07
  • 2013-09-01
  • 1970-01-01
  • 2011-02-26
相关资源
最近更新 更多