Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: DASHBY88 on March 15, 2024, 12:18:16 am
-
I'm currently trying to prototype an EA Model Add-In to control the modification to Connectors on a diagrams.
What I have below triggers correctly tells you you've modified and asks the question.
The change to the connector information is updated correctly, as far as I can tell because of point 4 below.
However:
1) The line Repository.SaveDiagram(dgmID); seems to not do anything the diagram is still flagged as modified;
2) The line Repository.ReloadDiagram(dgmID); seems to not do anything the diagram is still flagged as modified;
3) Replacing point 2 with Repository.RefreshOpenDiagrams(true); cause EA to close without any notice;
4) If you click Yes on closing the diagram to the save prompt, you get a new message saying your changing the connector from the new to the old again.
Any suggestions would be appreciated, or just shout if it's a bug that needs reporting.
const promptYESNO = 2
const resultYes = 3
const resultNo = 4
const dgmID = Repository.GetCurrentDiagram().DiagramID;
if (ot.val == EA.ObjectType.otConnector) {
if (this.oCon === GUID.val) { // Better double check we haven't changed context
let con = Repository.GetConnectorByGuid(GUID.val);
if(con !== null) {
let nSupplier = con.SupplierID;
if (this.oSupplier !== con.SupplierID) { //Supplier has changed
let oldSupplier = Repository.GetElementByID(this.oSupplier);
let nSupplier = Repository.GetElementByID(con.SupplierID);
let rsp = Session.Prompt("Connector supplier changed from " + oldSupplier.Name + " to " + nSupplier.Name + ".\n" +
"Are you sure you want to make this change?", promptYESNO);
if( rsp === resultNo) {
con.SupplierClientID = this.oSupplier;
con.Update();
Repository.AdviseConnectorChange(con.ConnectorID);
Repository.ReloadDiagram(dgmID);
nSupplier = this.oSupplier;
} else {
Session.Output("Saving diagram: " + dgmID);
Repository.SaveDiagram(dgmID);
}
}
// Set the old to new
this.oSupplier = nSupplier;
}
}
}
-
Thanks to finally finding the right question and answer in the forum I can now say that using the line
dgm.Update(); does in fact work. though oddly in the case of Aggregations this adds on the navigability arrow head to the diagram.
-
There's no reason at all to save your diagram, your are not changing anything to the diagram object.
The only thing you seem to be updating is the connector.
As a side-effect, it might trigger a redraw of the diagram, but that is also achieved by closign and re-opening the diagram.
You are doing something weird though
con.SupplierClientID = this.oSupplier;
con.Update();
SupplierClientID doesn't exist, and you are setting it to this.oSupplier which is presumably an object and not an ID.
Geert
-
Thanks Geert,
I did get this all working out in the end. The o in the field name was for old rather than object. One of the many reasons to not use Hungarian Case.