Reputation: 431
Does anybody know how to change the default scope for attributes of UML classes in Enterprise Architect (I am using version 9.2)? When adding a new attribute, it is by default set to Private. I am mainly using Enterprise Architect for data modelling, and all the attributes should be public.
Currently I have to manually change the scope from Private to Public for every single attribute I add, so I would save me quite some time if I could someway set the default scope for new attributes to Public.
Upvotes: 4
Views: 1866
Reputation: 4047
You can use the following script to change all private attributes to public in a package.
!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: If you still need some private attributes, you can add additional flag/character in the attribute name, then modify the above script to parse attribute name and only change it to public when you find the flag and remove the flag from the attribute name.
Upvotes: 2