Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 309 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Access to nested elements by script in Enterprise Architect

#1
I'm a beginner with Enterprise Architect and I need to write a little program to select all "Activity" type in a Enterprise Architect project to set a particular value of "Alias" property (not the same but following a particular logic).
I think to do this with the Scripting tool, but I had some difficulties to access to any activity object by scripting.

I found the link [1] "Enterprise Architect Object Model" but I could not solve my question.
Below is attached the project tree.

Here there is some javascript code i tried:

var elem as EA.Element;
elem = Repository.GetTreeSelectedObject();
elem.Alias = "Hi at all";

But this code has 2 problems:

1) it needs to select the activity with the mouse pointer;

2) after running the code the "Alias" field of the activity is empty.

[![enter image description here][2]][2]


[1]:
[2]:
Reply

#2
1. How to process all the Activities
--
There are different ways to deal with this. One option would be to start at the selected **Package** and iterate over each of the owned elements; and their owned elements.
That would be something like this (C#, but you get the gist of it):

public void main()
{
var selectedPackage = Repository.GetTreeSelectedPackage();
processPackage(selectedPackage);
}

private void processPackage(EA.Package package)
{
//process owned elements
foreach (EA.Element element in package.Elements)
{
processElement(element);
}
//process SubPackages
foreach(EA.Package subPackage in package.Packages)
{
processPackage(subPackage);
}
}
private void processElement(EA.Element element)
{
//test type and steroetype to make sure we only treat Activities
if (element.Type == "Activity" && element.Stereotype == "Activity")
{
element.Alias = "newAlias";
element.Update();
}
//process owned Elements
foreach(EA.Element subElement in element.Elements)
{
processElement(subElement);
}
}

This works OK for a limited number of elements, but it get real slow if you wanted to process larger numbers of elements scattered over a large model.

In that case it is better to use `Repository.GetElementSet(MySQLSelectQuery,2)`. Use this operation with an SQL query (second parameter needs to be `2`) to select exactly the elements you need.
This will be an order of magnitude faster then iterating over the whole model.

Examples of this approach (and much more) in my github repositories:

- C# [Enterprise Architect Add-in Framework][1]
- VBScript [Enterprise-Architect-VBScript-Library][2]

2. How to save updates
--
That is simple enough. Make sure to call `Update()` after changing any property of the API object.


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through