Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: McMannus on June 06, 2013, 01:15:09 am

Title: Z-order by  DiagramObject.Sequence does not work
Post by: McMannus on June 06, 2013, 01:15:09 am
Hi all,

I'm struggling with the DiagramObject.Sequence attribute.
My Code:

Code: [Select]
       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?
Title: Re: Z-order by  DiagramObject.Sequence does not wo
Post by: qwerty on June 06, 2013, 04:51:03 am
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.
Title: Re: Z-order by  DiagramObject.Sequence does not wo
Post by: Aaron B on June 06, 2013, 10:03:23 am
Try getting rid of the SaveDiagram() call.
Title: Re: Z-order by  DiagramObject.Sequence does not wo
Post by: Geert Bellekens on June 06, 2013, 05:00:33 pm
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
Title: Re: Z-order by  DiagramObject.Sequence does not wo
Post by: McMannus on June 06, 2013, 05:32:42 pm
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?
Title: Re: Z-order by  DiagramObject.Sequence does not wo
Post by: Geert Bellekens on June 06, 2013, 05:40:41 pm
EA doesn't do much automatically when using the API.

Geert
Title: Re: Z-order by  DiagramObject.Sequence does not wo
Post by: McMannus on June 06, 2013, 05:45:55 pm
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.
Title: Re: Z-order by  DiagramObject.Sequence does not wo
Post by: qwerty on June 06, 2013, 10:58:14 pm
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.
Title: Re: Z-order by  DiagramObject.Sequence does not wo
Post by: Geert Bellekens on June 07, 2013, 03:50:00 pm
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
Title: Re: Z-order by  DiagramObject.Sequence does not wo
Post by: McMannus on June 07, 2013, 04:48:34 pm
It's always the same tradeoffs API developers have to consider: Flexibility vs. Convenience ;)
Title: Re: Z-order by  DiagramObject.Sequence does not wo
Post by: Helmut Ortmann on November 29, 2013, 02:22:31 am
Hi,

I do it wirh SQL:

Code snippet:
Code: [Select]
string updateStr = @"update t_DiagramObjects set sequence = sequence + 1 "+
                       " where diagram_id = " + dia.DiagramID.ToString();

            rep.Execute(updateStr);
Code: [Select]
string updateStr = @"update t_DiagramObjects set sequence = " + sequence +
                       " where diagram_id = " + dia.DiagramID.ToString() +
                       " AND instance_id = " + obj.InstanceID.ToString();

            rep.Execute(updateStr);

Helmut