Search code examples
scriptingautomationenterprise-architectports

Enterprise architect: Automation scripting: Show created ports on element component in diagram


I am writing a Python script to create diagrams,elements in Enterprise Architect. I have created a port and attached it to the element but now i Need this port be visible on the element in the diagram view. I searched the available classes and packages in the documentation but couldn't find any function for element/port visability.

NB: I don't Need to do it from the program, i Need a scripting function, the scripting language is not an issue.

Thank you.


Solution

  • You just need to locate the element. Ports and other embedded elements are child elements. So look into parent.elements to retrieve the right element.

    Now placing it in a diagram is the same as with its parent. You create a diagramObject and place it at the right location on the border of the parent element. Something like this:

    dia_obj = diagram.DiagramObjects.AddNew ("l=10;r=110;t=-20;b=-80", "");
    dia_obj.ElementID = element.ElementID;
    dia_obj.Update ();
    Repository.ReloadDiagram (diagram.DiagramID);
    

    NB: In V10 (up to build 1006) the embedded element is not placed correctly but EA places it somewhere at the side of the embedding class. This bug has been fixed with V11 (build 1103).