'Enterprise Architect Sequencing With Python

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)  


Solution 1:[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).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1