4

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

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

4

1 回答 1

2

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

!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:如果还需要一些私有属性,可以在属性名中添加额外的flag/character,然后修改上面的脚本解析属性名,只有找到flag时才改为public,从属性名中去掉flag .

于 2013-06-21T09:51:52.640 回答