Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Hurra on September 22, 2021, 12:06:50 am
-
Hello!
I have made a script to automate the creation of an Operational-Connectivity diagram, based on an Operational-Process diagram (from the framework UAF).
I execute the script on an Operational-Connectivity diagram.
I find corresponding Operational-Process diagram.
I find OperationalRoles (represented as swimlanes) in the Operational-Process diagram, and add them to the Operational-Connectivity diagram.
I find where OperationalActivityActions cross swimlanes in the Operational-Process diagram, and add corresponding connectors between the OperationalRoles in the Operational-Connecitivity diagram.
What I'm trying to do now, is to hide all other connectors which comes with the elements added in the Operational-Connectivity diagram, to make an easy to view diagram.
Ez pz:
for ( var i = 0; i < currentDiagramLinks.Count; i++ )
{
var currentLink as EA.DiagramLink;
currentLink = currentDiagramLinks.GetAt( i );
var actualLink as EA.Connector;
actualLink = Repository.GetConnectorByID( currentLink.ConnectorID );
if ( <MY SHOW CONDITION> )
{
currentLink.IsHidden = true;
}
else
{
currentLink.IsHidden = false;
}
currentLink.Update();
}
This work, but I have to run the script twice.
It's like the script can't keep up with the changes. I have tried to update/save everything I can think of.
currentDiagramLinks.Count is always the same whatever I update/save. Unless I run the script again. Then it works as expected.
// Get a reference to the current diagram
var currentDiagram as EA.Diagram;
currentDiagram = Repository.GetCurrentDiagram();
Repository.SaveDiagram(currentDiagram.DiagramID);
// Get diagram links
var currentDiagramLinks as EA.Collection;
currentDiagramLinks = currentDiagram.DiagramLinks;
Any thoughts?
One thing I realized now I haven't tried is to do Repository.GetCurrentDiagram() again, but is that really necessary? I will keep on testing stuff until I get a response!
Cheers!
-
ok..
So adding currentDiagram = Repository.GetCurrentDiagram(); again seems to solve the issue.
But why isn't updates/saves enough? Now I don't know which updates/saves are redundant ::)
Someone that can explain?
-
I ran the following Python snippet:
dia = rep.GetDiagramByGUID("{B5F9F53C-570D-475b-A3D7-B64380F4A9DC}")
for l in dia.diagramLinks:
l.isHidden = True
l.update
That made all links vanish. As it should be.
Then I opened the diagram manually and made the connectors visible again. Running now
dia = rep.GetCurrentDiagram()
for l in dia.diagramLinks:
l.isHidden = True
l.update
still showed the connectors on the diagram. Of course, because a reload is missing. Just appending
rep.reloadDiagram(dia.diagramId)
made the changes visible.
q.