Configure your own default line styles in Enterprise Architect with EA-Matic

With EA-Matic you can develop add-ins for Enterprise Architect using the built-in scripting feature of EA.

With this EA-Matic script you can configure your own default line-styles depending on the type of connector.

In Enterprise Architect you can choose from no less then 9 different line style for the connectors.

Line Styles

Unfortunately you can only choose from the first three to be the default line style for new connectors.

line style default options

Additionally you can also specify the default for Generalization to be Tree Style.

For me that is not enough. I have my own habits when making UML diagrams. For most connector types I use Orthogonal – Square, but not for dependencies, use case relations and note links. For those I like the Direct style. The last exception are the control flow, state flow and object flows, for which I use Orthogonal – Rounded.


This EA-Matic script gives me the control I want. Not only does it set the default line style for new connectors, with the context menu I can reset all connectors on a diagram to my own default styles.

Free download

The code

In order to define your own preferred style you can edit the indicated part in the script

<br />
'*********EDIT BETWEEN HERE*************<br />
' set here the menu name<br />
menuDefaultLines = &quot;&amp;Set default linestyles&quot;</p>
<p>' set here the default style to be used<br />
defaultStyle = lsOrthogonalSquareTree</p>
<p>' set there the style to be used for each type of connector<br />
function determineStyle(connector)<br />
    dim connectorType<br />
    connectorType = connector.Type<br />
    select case connectorType<br />
        case &quot;ControlFlow&quot;, &quot;StateFlow&quot;,&quot;ObjectFlow&quot;,&quot;InformationFlow&quot;<br />
            determineStyle = lsOrthogonalRoundedTree<br />
        case &quot;Generalization&quot;, &quot;Realization&quot;, &quot;Realisation&quot;<br />
            determineStyle = lsTreeVerticalTree<br />
        case &quot;UseCase&quot;, &quot;Dependency&quot;,&quot;NoteLink&quot;<br />
            determineStyle = lsDirectMode<br />
        case else<br />
            determineStyle = defaultStyle<br />
    end select<br />
end function<br />
'************AND HERE****************<br />

This script uses 3 EA events. The first one is the EA_OnPostNewConnector which gets triggered by EA the moment you create  a new connector.

<br />
'the event called by EA<br />
function EA_OnPostNewConnector(Info)<br />
    'get the connector id from the Info<br />
    dim connectorID<br />
    connectorID = Info.Get(&quot;ConnectorID&quot;)<br />
    dim connector<br />
    set connector = Repository.GetConnectorByID(connectorID)<br />
    'get the current diagram<br />
    dim diagram<br />
    set diagram = Repository.GetCurrentDiagram()<br />
    if not diagram is nothing then<br />
        'first save the diagram<br />
        Repository.SaveDiagram diagram.DiagramID<br />
        'get the diagramlink for the connector<br />
        dim diagramLink<br />
        set diagramLink = getdiagramLinkForConnector(connector, diagram)<br />
        if not diagramLink is nothing then<br />
            'set the connectorstyle<br />
            setConnectorStyle diagramLink, determineStyle(connector)<br />
            'save the diagramlink<br />
            diagramLink.Update<br />
            'reload the diagram to show the link style<br />
            Repository.ReloadDiagram diagram.DiagramID<br />
        end if<br />
    end if<br />
end function<br />

The next even we use is the EA_GetMenuItems so we can show a menu option in the context menu of a diagram.

<br />
'Tell EA what the menu options should be<br />
function EA_GetMenuItems(MenuLocation, MenuName)<br />
    if MenuName = &quot;&quot; and MenuLocation = &quot;Diagram&quot; then<br />
        'Menu Header<br />
        EA_GetMenuItems = menuDefaultLines<br />
    end if<br />
end function<br />

The last EA event is the EA_MenuClick, triggered when the user actually clicks on the menu item.

<br />
'react to user clicking a menu option<br />
function EA_MenuClick(MenuLocation, MenuName, ItemName)<br />
    if ItemName = menuDefaultLines then<br />
        dim diagram<br />
        dim diagramLink<br />
        dim connector<br />
        dim dirty<br />
        dirty = false<br />
        set diagram = Repository.GetCurrentDiagram<br />
        'save the diagram first<br />
        Repository.SaveDiagram diagram.DiagramID<br />
        'then loop all diagramLinks<br />
        if not diagram is nothing then<br />
            for each diagramLink in diagram.DiagramLinks<br />
                set connector = Repository.GetConnectorByID(diagramLink.ConnectorID)<br />
                if not connector is nothing then<br />
                    'set the connectorstyle<br />
                    setConnectorStyle diagramLink, determineStyle(connector)<br />
                    'save the diagramlink<br />
                    diagramLink.Update<br />
                    dirty = true<br />
                end if<br />
            next<br />
            'reload the diagram if we changed something<br />
            if dirty then<br />
                'reload the diagram to show the link style<br />
                Repository.ReloadDiagram diagram.DiagramID<br />
            end if<br />
        end if<br />
    end if<br />
end function<br />

Then we have a small helper function to get the diagramLink object from the diagram

<br />
'gets the diagram link object<br />
function getdiagramLinkForConnector(connector, diagram)<br />
    dim diagramLink<br />
    set getdiagramLinkForConnector = nothing<br />
    for each diagramLink in diagram.DiagramLinks<br />
        if diagramLink.ConnectorID = connector.ConnectorID then<br />
            set getdiagramLinkForConnector = diagramLink<br />
            exit for<br />
        end if<br />
    next<br />
end function<br />

And last but not least the method that will actually set the connector style.

<br />
'actually sets the connector style<br />
function setConnectorStyle(diagramLink, connectorStyle)<br />
    'split the style into its parts<br />
    dim styleparts<br />
    dim styleString<br />
    styleString = diagramLink.Style<br />
    styleparts = Split(styleString,&quot;;&quot;)<br />
    dim stylePart<br />
    dim mode<br />
    dim modeIndex<br />
    modeIndex = -1<br />
    dim tree<br />
    dim treeIndex<br />
    treeIndex = -1<br />
    mode = &quot;&quot;<br />
    tree = &quot;&quot;<br />
    dim i<br />
    'find if Mode and Tree are already defined<br />
    for i = 0 to Ubound(styleparts) -1<br />
        stylePart = styleparts(i)<br />
        if Instr(stylepart,&quot;Mode=&quot;) &gt; 0 then<br />
            modeIndex = i<br />
        elseif Instr(stylepart,&quot;TREE=&quot;) &gt; 0 then<br />
            treeIndex = i<br />
        end if<br />
    next<br />
    'these connectorstyles use mode=3 and the tree<br />
    if  connectorStyle = lsTreeVerticalTree or _<br />
        connectorStyle = lsTreeHorizontalTree or _<br />
        connectorStyle = lsLateralHorizontalTree or _<br />
        connectorStyle = lsLateralVerticalTree or _<br />
        connectorStyle = lsOrthogonalSquareTree or _<br />
        connectorStyle = lsOrthogonalRoundedTree then<br />
        mode = &quot;3&quot;<br />
        tree = connectorStyle<br />
    else<br />
        mode = connectorStyle<br />
    end if<br />
    'set the mode value<br />
    if modeIndex &gt;= 0 then<br />
        styleparts(modeIndex) = &quot;Mode=&quot; &amp; mode<br />
        diagramLink.Style = join(styleparts,&quot;;&quot;)<br />
    else<br />
        diagramLink.Style = &quot;Mode=&quot; &amp; mode&amp; &quot;;&quot;&amp; diagramLink.Style<br />
    end if<br />
    'set the tree value<br />
    if treeIndex &gt;= 0 then<br />
        if len(tree) &gt; 0 then<br />
            styleparts(treeIndex) = &quot;TREE=&quot; &amp; tree<br />
            diagramLink.Style = join(styleparts,&quot;;&quot;)<br />
        else<br />
            'remove tree part<br />
            diagramLink.Style = replace(diagramLink.Style,styleparts(treeIndex)&amp;&quot;;&quot; , &quot;&quot;)<br />
        end if<br />
    else<br />
        diagramLink.Style = diagramLink.Style &amp; &quot;TREE=&quot; &amp; tree &amp; &quot;;&quot;<br />
    end if<br />
end function<br />

25 thoughts on “Configure your own default line styles in Enterprise Architect with EA-Matic

  1. Just another thing I missed a lot, which I could possibly develop for myself, but for which I never had the time to do. 🙂

    I simply can’t understand why the choice of line styles is restricted in the Options panel, but I’d bet they simply forger to extend it when newer styles became available.

    1. Yes indeed. I’m sure they know about it, and plan to extend the choices in the future, but I guess these type of change request often have to make room for more urgent changes.

  2. Some help please. I’ve imported the script to EA. EA-Matic correctly shows the monitored events and lists the event handler routines. Yet, if I create a line, it will default to what is set in EA options, instead of being of that style set for that kind of element. (More precisely, I am trying to link an actor with a use case, using the script default lsDirectMode for use cases..

    1. Hi,

      It looks like the script isn’t being triggered when you create a new connector. To make sure you can put a line such as
      MsgBox “the script has been triggered”
      in the EA_OnPostNewConnector(Info) function.

      If this doesn’t work I’m happy to have a look at the script if you send it to me by email.


  3. Gonna send in an email, I’ve inserted a breakpoint at the beginning of a function, but that has not been triggered.

      1. That’s good to know! Now I guess you are reading the texts of scripts and putting them into eval() functions to have them executed. Don’t tell me if I figured it out correctly by any chance, that’s your trade secret. 😉

  4. Hi Geert

    I too am trying to recreate the above script.

    I’m getting “An error occurred while attempting to communicate with an Addin:” message when I select EA-Matic/Options. “EA_MenuClick: Method not found: ‘Boolean EAAddinFramework.EASpecific.Script.get_isStatic()’.”

    Hope you can help!


    1. Hi Simon,

      Can you confirm that
      – You have installed the latest version of EA-Matic (now part of the Bellekens EA Toolpack version 1.0.10)
      – You don’t have any previous versions of EA-Matic or EA Navigator still installed?

      It looks like it is using a part of the framework from an older version. That could happen if you still have an older version of EA-Matic or EA Navigator installed.

      Uninstalling all of my add-ins, and installed only the latest Bellekens EA Toolpack will probably sort this out.

      Let me know how it works out.


  5. Hi Geert

    Many thanks for your speedy reply.

    I think I have solved the problem – I had an old EA Navigator installed. Have uninstalled everything and reinstalled and now seems to be working.

    Just need to get the script working- Is the full script available anywhere rather than just the fragments? Or can you tell me where lsOrthogonalSquareTree etc are defined?


      1. Brilliant!

        Many thanks. And thanks for making EA-Matic avaialble. A fantastic utility.


  6. Hi Geert,

    I am trying to set default line styles for the connectors using your EA-Matic script. I have downloaded the script and imported it into Enterprise architects from Project => Data Management => Import Reference Data. Now, how can i set the default line style to my diagram? How to proceed further?

      1. Hi Geert,
        Thanks for the quick replay. Now am able to set my default line style to all my connectors in my project. It really helped a lot geert. Thanks for your support.

  7. Hi Geert,

    I have downloaded the EA-Matic script into EA from Project => DataManagement => Import Reference Data. But i didn’t get any menu item like “EA-Matic” in Extensions menu. I am trying to set default line sytle to OrthogonalSquare. How to proceed further? Any help would be much appreciated.


      1. Hi Geert,
        Thanks for the quick replay. Now, i have installed EA-Matic add-in and am able to set my default line style. It really helped a lot geert. Thanks for your support.

  8. Hello, Geert,
    This is a super add-in to EA!

    Could you help with the question:
    How to include to EA-matic-script my own script with the common functions?

    For example, this code doesn’t work:
    _autoUpdate / testCommonFunction:

    !INC Local Scripts.EAConstants-JScript
    !INC MyTools.CommonFunctions

    function EA_OnPreDeleteConnector(Info)


    function commonTest(x) {
    var el = Repository.GetElementByGuid(“{3E123F58-D758-4f9e-8E322-9029A8C632DD}”);
    el.Name = “tst ” + x


    and generates the error, that commonTest() couldn’t be found.

    Run “_autoUpdate / testCommonFunction” from the original EA works fine (with the uncommented “commonTest(“_”)” ).

    Thank you.


  9. Posting this to help those not so versed with EA-matic or how to load this script.

    Steps to load Default Line script:

    1. Download the default line script using the free download link on this page (do not try to cope/paste this code sections on this page and create your own script unless you know how because it will be missing stuff)

    2. save it to a local known location

    3. In EA go to Project|Data Management|Import Reference Data and choose the file you saved. You should see the script loaded under the ‘Model Scripts’ folder in your scripting area. If the folder was not there before it will create it. You can open the scripting area by going to Tools|Scripting

    4. Double click the script and edit the top portion as wanted for your preferences.

    5. Click save (YOU DO NOT NEED TO RUN).

    6. Go to Extensions|EA-Matic|Settings. Make sure the three wanted functions are checked and click OK you should not have to change anything but doing this reloads EA-Matic and the script. If you make any more changes do this again.

    7. You should be good to go to try out the connectors on your diagram.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.