如何在Enterprise Architect中将属性的默认范围从Private更改为Public?

时间:2013-06-07 15:15:47

标签: enterprise-architect

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

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

1 个答案:

答案 0 :(得分:1)

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

!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();

提示:如果您仍需要一些私有属性,可以在属性名称中添加其他标记/字符,然后修改上面的脚本以解析属性名称,并在找到时将其更改为公共标志并从属性名称中删除标志。

相关问题