Author Topic: Connector Change API and Diagram Saving appears broken  (Read 10544 times)

DASHBY88

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Connector Change API and Diagram Saving appears broken
« 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
Code: [Select]
Repository.SaveDiagram(dgmID); seems to not do anything the diagram is still flagged as modified;
 2) The line
Code: [Select]
Repository.ReloadDiagram(dgmID); seems to not do anything the diagram is still flagged as modified;
 3) Replacing point 2 with
Code: [Select]
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.

Code: [Select]
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;
}
}
}

DASHBY88

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Connector Change API and Diagram Saving appears broken
« Reply #1 on: March 15, 2024, 12:58:14 am »
Thanks to finally finding the right question and answer in the forum I can now say that using the line
Code: [Select]
dgm.Update(); does in fact work. though oddly in the case of Aggregations this adds on the navigability arrow head to the diagram.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13286
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Connector Change API and Diagram Saving appears broken
« Reply #2 on: March 15, 2024, 01:30:29 am »
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

Code: [Select]
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



DASHBY88

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Connector Change API and Diagram Saving appears broken
« Reply #3 on: April 30, 2024, 11:01:29 pm »
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.