-2

I am starting to use Python for automating Enterprise Architect. I am unable to change the sequencing of an element with the code below. What am I doing wrong? What is the good way of using DiagramObjects.Sequence?

TestDiagEl=diagram.DiagramObjects.AddNew(<validlocation>,"ArchiMate_Capability")
TestDiagEl.Sequence="99"
TestDiagEl.Update()
TestDiagEl.ElementID=element1.ElementID
TestDiagEl.Update()
eaRep.ReloadDiagram(diagram.DiagramID)  
qwerty_so
  • 35,448
  • 8
  • 62
  • 86
  • 1
    Why do you have two calls to Update? Are you trying to update the sequence before setting the ElementID? Because that would lead to an error. You can't save a DiagramObject without ElementID – Geert Bellekens Apr 19 '22 at 06:36
  • Should i "AddNew> ElementID > Update > Sequence >Update ? – Sedat YILMAZ Apr 19 '22 at 07:00
  • Why do you do two updates? For each line of code you should know exactly why you are writing it, otherwise you are doing *programming by incantation*. Another one, what's the reason for the `ArchiMate_Capability` parameter you pass to the `AddNew` method? – Geert Bellekens Apr 19 '22 at 08:03

1 Answers1

1

Remove the first Update since at that position the important reference ElementID is not set and EA will run into trouble.

Further the 2nd parameter of AddNew is supposed to be an empty string. Not sure what EA will do with it, if you supply something else.

Finally Sequence is int and not string (though Python is forgiving in such cases as I have just tested and it will internally do int(<parameter>) which then might raise an exception).

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
  • 1
    Also: the property Sequence is a Long, not a string, so it will error when passing a string. Pfew, 6 lines, 3 errors, that's 50% – Geert Bellekens Apr 19 '22 at 08:06
  • @GeertBellekens Correct. I think that Python will do the casting automagically but not 100% sure. Will amend my answer. – qwerty_so Apr 19 '22 at 09:08
  • TestDiagEl=diagram.DiagramObjects.AddNew(generatePosString(l,r,t,b),"") TestDiagEl.ElementID=element1.Elements.GetAt(sayici).ElementID TestDiagEl.Update() eaRep.ReloadDiagram(diagram.DiagramID) i did the changes that you guys asked. AFAIK int() casts to long for Python. This didnot resolve my problem I still get the exact same reults as the question. – Sedat YILMAZ Apr 19 '22 at 12:34
  • Well, lots of reasons can be the cause. Don't expect someone to be clairevoyant. – qwerty_so Apr 19 '22 at 13:18
  • Is there a way that you can provide a simple yet working code for this ? I would rather prefer python but any language would work. how can i use seqeuence ? – Sedat YILMAZ Apr 19 '22 at 14:06
  • It would be the above which works. You must be doing something wrong elsewhere. See my previous comment. – qwerty_so Apr 19 '22 at 14:28
  • I have solved the issue. The problem fixed when i entered Sequence data for every single object rather than just the one that i want. – Sedat YILMAZ Apr 20 '22 at 12:36