Author Topic: Auto Routing a Diagram from API?  (Read 14788 times)

Rich Anderson

  • EA User
  • **
  • Posts: 142
  • Karma: +8/-0
    • View Profile
    • LinkedIn
Auto Routing a Diagram from API?
« on: August 01, 2019, 10:40:12 pm »
Hi There, I'm generating lots of diagrams (many hundreds) and would like to automatically invoke the Auto Route layout that leaves the diagram objects in place while orthogonally routing the connectors.  This is easily accessible from the Layout menu in the UI.

I found this discussion that pointed me most of the way there...
https://www.sparxsystems.com/forums/smf/index.php/topic,4947.msg122807.html#msg122807

... but I cannot seem to find the right code or argument that would invoke the auto-route function.   

I can get a handle to the LayoutDiagramEx method like this...

Code: [Select]
        Dim thisProject As EA.Project
        thisProject = earepository.GetProjectInterface()
        Dim thisDiagram As EA.Diagram = earepository.GetDiagramByGuid("{99927EFC-BA32-4e0b-A6AC-5D4605524E51}")
        thisProject.LayoutDiagramEx(thisDiagram.DiagramGUID, ConstLayoutStyles.lsCrossReduceAggressive, 4, 20, 20, False)

... and I've tried all the different enumerations that are described here...

https://www.sparxsystems.com/enterprise_architect_user_guide/15.0/automation/constlayoutstylesenum.html

... and also says this...

Quote
The enum values defined here are used exclusively for the 'Lay Out a Diagram' method. You use these values to define the layout options as provided by the 'Layout > Tools > Diagram Layout ' ribbon option.

... but that doesn't seem to be the case!   Any suggestions?


Rich Anderson
Urgnt Limited

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Auto Routing a Diagram from API?
« Reply #1 on: August 02, 2019, 05:04:19 am »
The auto-layout sometimes for small diagrams gives a starting point. For complex ones it, well, does something so I finally have to do it manually anyway. Anyhow, have you tried with an earlier EA version? It's not new to V15.

q.

Rich Anderson

  • EA User
  • **
  • Posts: 142
  • Karma: +8/-0
    • View Profile
    • LinkedIn
Re: Auto Routing a Diagram from API?
« Reply #2 on: August 02, 2019, 05:52:18 am »
Actually, what I have is a lot of small diagrams with swimlanes that I'm generating with code (many hundreds) that are modeling real estate ownership structures.  For the great majority of these diagrams the auto-route is surprisingly good -- certainly much faster than me doing it by hand.  I've tried this in v14 and it works well there and I understand it has been around for a while.

If I could just figure out how to invoke Auto Route with code through the API, life would be sweet!   Otherwise, I have to go an click through hundreds of diagrams or find some way to apply RPA (yuck).   
Rich Anderson
Urgnt Limited

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Auto Routing a Diagram from API?
« Reply #3 on: August 02, 2019, 06:23:57 am »
Unless someone beats me or I forget it :-/ I'll have a look into that this weekend.

q.

Rich Anderson

  • EA User
  • **
  • Posts: 142
  • Karma: +8/-0
    • View Profile
    • LinkedIn
Re: Auto Routing a Diagram from API?
« Reply #4 on: August 02, 2019, 10:10:38 am »
 :) :) :) :)  Thank you!
Rich Anderson
Urgnt Limited

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Auto Routing a Diagram from API?
« Reply #5 on: August 02, 2019, 10:45:28 pm »
Hm. The code works for me, but you probably have another issue here. You're talking about auto-route. That's got nothing to do with the layout function but with connector properties. You's need to alter diagram connectors to the auto-route style.

q.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Auto Routing a Diagram from API?
« Reply #6 on: August 03, 2019, 06:28:15 pm »
I just browsed the available layout options - and yes: there's an Auto Route. As so often the help is silent here. ConstLayoutStyles has nothing matching for "Auto". Will look again.

q.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Auto Routing a Diagram from API?
« Reply #7 on: August 03, 2019, 06:47:48 pm »
Just a rant in between: Where the heck is that scripting stuff (V14)? Where is my menu??? This Search is good for nothing. It lists 4 results: "analyzer script" enabled and 3 non-enabled. But non pointing me to that scripting window. The help blabbers about a Code ribbon but there is none. Aaaaaaaargh

I will open an elder EA version where I know it's there

q.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Auto Routing a Diagram from API?
« Reply #8 on: August 03, 2019, 06:55:53 pm »
There is a constant
Code: [Select]
lsProgramDefault = &HFFFFFFFFwhich tells me that there must be a way to set a layout format as program default. I have not the faintest idea how. But if you manage to do that you can set this Auto layout as such and use this parameter for your mass layout.

q.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Auto Routing a Diagram from API?
« Reply #9 on: August 04, 2019, 02:05:47 am »
P.S. I found that layout option in EA's option jungle :-/
- Open the diagram properties (where else?)
- Select Diagram (what else?)
- Click Select Layout Style (huh, what for if all layouts have their own button?)
- And there find Set as Project Default (soooo easy)

Now, what about that Auto Layout? Yes, you can't set it. The options seem to match the options in that Constants file, though. Obviously there are a couple of layout options that did not make it into the API.

Have fun with your manual layout. Send a feature request. Good luck.

q.

Rich Anderson

  • EA User
  • **
  • Posts: 142
  • Karma: +8/-0
    • View Profile
    • LinkedIn
Re: Auto Routing a Diagram from API?
« Reply #10 on: August 04, 2019, 02:04:04 pm »
Thanks for all your time in looking into this.   I thought it would help if I made a short screen cam to illustrate what's going on.  (I made it before I saw all your responses, but I think it's still relevant).   

https://www.youtube.com/watch?v=eqE3U1SKhk4&feature=youtu.be

As you can see, I can set all the connectors to AutoRoute, but that doesn't quite do it.  When I invoke the AutoRoute operation from the UI, then it moves all the lines around, avoiding crossing, and then sets the line styles to Custom (go figure).  All I want is a command that looks like this...

Code: [Select]
MyDiagram.ApplyLayout ("AutoRoute")

... that will just do what I'm doing with the UI.  I would expect that to be a diagram method I would find documented here...

https://sparxsystems.com/enterprise_architect_user_guide/15.0/automation/diagram2.html

But, alas, no.  So, maybe that's what I should ask for? 

So, it looks like my best option is to RPA it somehow or use AutoIT, because I literally have hundreds of these.
« Last Edit: August 04, 2019, 02:12:17 pm by Rich Anderson »
Rich Anderson
Urgnt Limited

philchudley

  • EA User
  • **
  • Posts: 743
  • Karma: +21/-0
  • EA Consultant / Trainer - Sparx Europe
    • View Profile
Re: Auto Routing a Diagram from API?
« Reply #11 on: August 06, 2019, 06:21:55 pm »
Joining the thread a little late, the method I used was:

1) Get the diagram
2) Get the diagramlinks for the diagram
3) Iterate all diagram links and set the linestyle for each link to autoroute (but not for generalisations or self relationships

Below is how I did it in C#, but could be translated easily to a scripting language

            EA.Collection theDiagramLinks = theDiagram.DiagramLinks;

            // iterate
            foreach (EA.DiagramLink currentLink in theDiagramLinks)
            {
                EA.Connector currentConnector = repository.GetConnectorByID(currentLink.ConnectorID);
                if (currentConnector.Type == "Association")
                {
                    // Is this a self association?
                    if (currentConnector.ClientID != currentConnector.SupplierID)
                    {
                        // No, so change the linestyle to Auto Route
                        //
                        currentLink.LineStyle = EA.LinkLineStyle.LineStyleAutoRouting;
                    }
                }
                else if (currentConnector.Type == "Generalization")
                {
                    // Change the linestyle to Tree Style Vertical
                    currentLink.LineStyle = EA.LinkLineStyle.LineStyleAutoRouting;
                }
                currentLink.Update();
            }
            repository.SaveDiagram(vocabularyDiagram.DiagramID);
        }

Hope this helps

All the best

Phil
Models are great!
Correct models are even greater!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Auto Routing a Diagram from API?
« Reply #12 on: August 06, 2019, 08:09:19 pm »
Hi Phil,
likely that's what internally happens (and which irritated me in the first attempt). The way to go (for Sparx) is to make such GUI enablements also be available for the API (that should be easy, shouldn't it?).

q.

Rich Anderson

  • EA User
  • **
  • Posts: 142
  • Karma: +8/-0
    • View Profile
    • LinkedIn
Re: Auto Routing a Diagram from API?
« Reply #13 on: August 07, 2019, 05:28:38 am »
Thanks, Phil.  I was able to get your code to work once I added a ReloadDiagram method to the end to update the links. (Thanks to qwerty's book!).   However, the results were not great.  The AutoRoute invoked from the UI does a much more clever job of routing the connectors and then leaves them as Custom type (not AutoRoute) when it's done.  If you create a test diagram and run your code first and then run the AutoRoute from the UI, you can see the difference.   

So, I'm really back to just wanting to invoke the same method as invoked from the UI.  Right now, it looks like my only option is to try to RPA it with UIPath or AutoIt.   This seems like such a basic thing left out of the API to me. 
Rich Anderson
Urgnt Limited

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Auto Routing a Diagram from API?
« Reply #14 on: August 07, 2019, 07:11:09 am »
Your only option is to ask for opening the API for this new feature. Too bad you did not join some 15 years ago where you got the request realized the next week. Another proof that in the good ole days everything was better :-/ (Of course EA was much more limited those days.)

q.