Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: McMannus on June 06, 2013, 01:15:09 am
-
Hi all,
I'm struggling with the DiagramObject.Sequence attribute.
My Code:
public static void putElementInDiagram(EA.Repository Repository, EA.Element element, ElementLayout layout, int diagramID)
{
EA.Diagram diagram = Repository.GetDiagramByID(diagramID);
EA.DiagramObject newDiagObject = diagram.DiagramObjects.AddNew(layout.getEAPosString(), "");
newDiagObject.ElementID = element.ElementID;
newDiagObject.Sequence = 1;
newDiagObject.Update();
Repository.SaveDiagram(diagramID);
Repository.ReloadDiagram(diagramID);
}
To my knowledge, newDiagObject.Sequence = 1 brings the diagram object in front of all others. Unfortunately, this has no effect to the t_diagramobjects table, although I invoke the Update method.
Any advice?
-
I'm using the current build and had no problem with above code. I assigned seq. 12 and that was a) reflected in t_diagramobjects and b) displayed correctly on the diagram.
q.
-
Try getting rid of the SaveDiagram() call.
-
There is a subtle difference between Repository.SaveDiagram() and Diagram.Update().
Repository.SaveDiagram() will the save the unsaved changes in an opened diagram.
Diagram.Update() will save the changes you have made to the EA.Diagram object in memory (and thus ignore all unsaved changes on the opened diagram)
So since you are calling Repository.SaveDiagram() it it saving the object in the memory of the EA GUI, and not the object your are working with in your add-in.
But in this particular case you don't even need to save the diagram because you are not changing anything to the diagram, only to a DiagramObject.
Geert
-
Well, I just tried my code again with one element and Sequence=12 as qwerty suggested. This worked! But am I wrong when I think of a setting where I have multiple objects with sequences 1,2,3,4,5,... and just add a new DiagramObject at Sequence=1 to bring it in front of all others, so that EA automatically increases all other sequence numbers by one automatically?
-
EA doesn't do much automatically when using the API.
Geert
-
I see, unfortunately not a very consistent approach, since one would assume that EA takes care in its API that the invariant "only one diagramobject per layer" is always true, no matter what is assigned to any sequence number.
-
Sparx' definition of consistency is obviously different to that of many users posting here. As Geert said: if you're using the API then YOU are responsible. That goes for quite some other use cases too - even worse.
q.
-
I always consider the API as a very thin layer around the actual database. So not much different to actually working with the database directly.
And don't forget, there's hardly any constraint defined on that database :'(
Geert
-
It's always the same tradeoffs API developers have to consider: Flexibility vs. Convenience ;)
-
Hi,
I do it wirh SQL:
- Add 1 to all sequences of diagram (sql update)
- Create & update() DiagramObject with EA API
- Add 1 to sequence of just created DiagramObject (sql update)
Code snippet:
string updateStr = @"update t_DiagramObjects set sequence = sequence + 1 "+
" where diagram_id = " + dia.DiagramID.ToString();
rep.Execute(updateStr);
string updateStr = @"update t_DiagramObjects set sequence = " + sequence +
" where diagram_id = " + dia.DiagramID.ToString() +
" AND instance_id = " + obj.InstanceID.ToString();
rep.Execute(updateStr);
Helmut