Since I'm a fairly new user when it comes to the Enterprise Architect, I'm stuck at this problem.
I need to write a script to transform each item marked as <<property>>
in the class diagram, into an attribute of that particular class.
So far, I've come to this and I am not sure how can I change each property into an attribute.
When I try to add a new attribute like this:
selectedObject.Attributes.AddNew("example", "int");
It crashes with an error that this collection is null or not an object.
Even when I add an attribute to the class manually and then try to access it with the method selectedObject.Attributes.GetAt(0);
it still crashes with the error:
Script.script 'Attributes' is null or not an object, Line: 39.
Below is my full code:
var currentDiagram as EA.Diagram;
currentDiagram = Repository.GetCurrentDiagram();
if ( currentDiagram != null )
{
// Get a reference to any selected connector/objects
var selectedObjects as EA.Collection;
selectedObjects = currentDiagram.SelectedObjects();
if ( selectedObjects.Count > 0 )
{
// One or more diagram objects are selected
var selectedObject as EA.Element;
for(var i = 0; i < selectedObjects.Count; ++i)
{
selectedObject = selectedObjects.GetAt(i);
Session.Output(selectedObject.Attributes.GetAt(0));
selectedObject.Attributes.AddNew("example", "int");
}
Session.Output(selectedObject.Name);
}