Author Topic: Script to Convert Current Lines to Any Style  (Read 5057 times)

rothnic

  • EA User
  • **
  • Posts: 91
  • Karma: +0/-0
    • View Profile
Script to Convert Current Lines to Any Style
« on: August 29, 2013, 04:26:41 pm »
Finally got around to dealing with the issue of not being able to quickly change line styles to anything I want. I put together this script using JScript that you can configure to convert all lines on the current diagram to any of the available styles. I figured it may be useful to others as well, so posted it via pastebin below.

It is available through the right click menu when in a diagram. I put it together this way because I was hoping to be able to use the prompt box, but can't find any way to do that besides just an "ok" prompt. Is that documentation somewhere?

For now, you can copy it over and over for each line type. It might be a bit messy since all of the logic to move back and forth between any line style, without affecting your current work or styles is in mostly one function.


[size=12]Script Can be Copied From Here:[/size] http://pastebin.com/1MKrf1CH






« Last Edit: August 30, 2013, 02:04:17 am by rothnic »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +564/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Script to Convert Current Lines to Any Style
« Reply #1 on: August 29, 2013, 06:09:15 pm »
Cool,

I added a function to one of my add-ins to do the same thing (but only limited to linestyle orthogonal square).

Here the important bit of code:

Code: [Select]
       /// <summary>
        /// set all links to (orthogonal - square)
        /// To do se we need to set Mode=3 and TREE=OS in the style of the diagramlinks
        /// </summary>
        public void setLinkStyles()
        {
            bool updated = false;
            foreach (EA.DiagramLink link in this.wrappedDiagram.DiagramLinks)
            {
                string linkStyle = link.Style;
                //updated mode to 3
                if (linkStyle.Contains("Mode="))
                {
                    int modeBegin = linkStyle.IndexOf("Mode=") + "Mode=".Length;
                    string mode = linkStyle.Substring(modeBegin,1);
                    if (mode != "3")
                    {
                        linkStyle = linkStyle.Replace("Mode=" + mode,"Mode=3");
                    }
                }
                else
                {
                    linkStyle = "Mode=3;"+linkStyle;
                }
                //update style to OS
                if (linkStyle.Contains("TREE="))
                {
                    int modeBegin = linkStyle.IndexOf("TREE=") + "TREE=".Length;
                    string treeStyle = linkStyle.Substring(modeBegin, 2);
                    if (treeStyle != "OS")
                    {
                        linkStyle = linkStyle.Replace("TREE=" + treeStyle, "TREE=OS");
                    }
                }
                else
                {
                    linkStyle = linkStyle + "TREE=OS;" ;
                }

                //only need to save the link when we have actually updated its style.
                if (link.Style != linkStyle)
                {
                    link.Style = linkStyle;
                    link.Update();
                    updated = true;
                }
            }
            //reload the diagram if we updated it.
            if (updated)
            {
                this.model.getWrappedModel().ReloadDiagram(this.wrappedDiagram.DiagramID);
            }
        }

Geert

rothnic

  • EA User
  • **
  • Posts: 91
  • Karma: +0/-0
    • View Profile
Re: Script to Convert Current Lines to Any Style
« Reply #2 on: August 30, 2013, 01:59:00 am »
Yeah I put it together for the same purpose, and it is fairly simple in that case. I think you don't even need to set the mode. It gets messier trying to not lose existing formatting, and setting mode and tree, and sometimes removing tree from the style. I need to go back and clean it up.

My key limitation is using government computers, where no one is given access to adding registry values, so i could use an add-in.

Is there anyway to provide a popup of some kind via scripting, that allows user entry, or selection? I could find no documentation on the use of Session.Prompt.
« Last Edit: August 30, 2013, 02:03:17 am by rothnic »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +564/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Script to Convert Current Lines to Any Style
« Reply #3 on: August 30, 2013, 03:38:01 pm »
I'm not sure (since I don't use scripting) but I think I've seen some topics go by that suggested it should be possible somehow.

Have you tried searching the forum (using the top left search button)

Geert

rothnic

  • EA User
  • **
  • Posts: 91
  • Karma: +0/-0
    • View Profile
Re: Script to Convert Current Lines to Any Style
« Reply #4 on: August 30, 2013, 09:32:13 pm »
Quote
I'm not sure (since I don't use scripting) but I think I've seen some topics go by that suggested it should be possible somehow.

Have you tried searching the forum (using the top left search button)

Geert

Yeah, just tried the one on the left side. I've also checked in all the help documentation, and checked online thinking it might be something pulled from Microsoft. Nothing about Session, or PromptType.

Sparx shows in the recent tutorial video how to connect scripting and the UI modeling portion of EA. But I think that has to be in the context of a simulation.

It would be kind of neat if you could connect the scripting capability with the UI modeling because you could recreate a portion of the add-in capability in that way.

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Script to Convert Current Lines to Any Style
« Reply #5 on: October 01, 2013, 04:23:05 am »
Hi,

may be my Addin in the community will help you:
http://community.sparxsystems.com/community-resources/745-toolset-to-set-linestyle-quick-search-and-a-lot-more

You just have to select
  • Diagram
  • Diagram element(s)
  • Diagram link


and click on the wanted line style.

The new is that there is no need to go a long way by context, extensions,.. If you choose the wrong line style: No problem, try another one. The selection is preserved.

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

rothnic

  • EA User
  • **
  • Posts: 91
  • Karma: +0/-0
    • View Profile
Re: Script to Convert Current Lines to Any Style
« Reply #6 on: October 01, 2013, 11:30:17 pm »
Quote
Hi,

may be my Addin in the community will help you:
http://community.sparxsystems.com/community-resources/745-toolset-to-set-linestyle-quick-search-and-a-lot-more

You just have to select
  • Diagram
  • Diagram element(s)
  • Diagram link


and click on the wanted line style.

The new is that there is no need to go a long way by context, extensions,.. If you choose the wrong line style: No problem, try another one. The selection is preserved.

Helmut

Thanks, yeah something like that is ideal. Unfortunately at work we can only install "approved" and tested applications, and only administrators can do it. So, I cannot use add-ins at all and can only do it via scripting.

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Script to Convert Current Lines to Any Style
« Reply #7 on: October 02, 2013, 04:20:35 am »
Hi,

I know of this restrictions. Happily I mostly have local administration rights.

It's possible to set line style by script. In the forum you find good solutions.

With this addin it's just a click. With scripts it's some clicks.

Thanks for your response,

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)