Book a Demo

Author Topic: Toggle Diagram Elements Programmatically  (Read 5175 times)

SteveC

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Toggle Diagram Elements Programmatically
« on: September 25, 2018, 09:07:02 am »

Does anyone know how to turn off namespace on a diagram programmatically?

I am looking for something I can call on the EA.Diagram to turn off namespace display on diagrams I create.

I have a reference to an EAD.Diagram (diagram) being created.  I have a local class called UmlDiagram (umlDiagram) which is a generic type used to hold diagram properties. I can toggle tags with code like this:
Code: [Select]
string style = CompileStyle(umlDiagram);
if (style.Length > 0) {
    diagram.ExtendedStyle = style;
    diagram.Update();
}

... and a CompileStyle method like this:
Code: [Select]
private string CompileStyle(UmlDiagram umlDiagram) {
    StringBuilder b = new StringBuilder();
    if (umlDiagram.ShowTags) {
        b.Append("ShowTags=1;");
    }
    return b.ToString();
}

I thought I could add code to the CompileStyle method, but it appears that using ShowForeign=0; does not work like ShowTags=0; in the extended style string.

What is the proper way to toggle diagram appearance elements through the API?


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Toggle Diagram Elements Programmatically
« Reply #1 on: September 25, 2018, 07:27:37 pm »
You need to check if the tag is already present in the list. In that case you need to alter its assignment after the "=". Just adding the attribute again to the list will confuse EA and behave arbitrarily.

q.

SteveC

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Toggle Diagram Elements Programmatically
« Reply #2 on: September 26, 2018, 01:23:07 am »
After I create the diagram, the list is empty, diagram.ExtendedStyle returns an empty string so there is nothing to replace. Do I have to make some other call to populate the ExtendedStyle property?

The above approach seems to work with ShowTags just fine. Is there some trick to setting "show namespace" with HighlightForeign?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Toggle Diagram Elements Programmatically
« Reply #3 on: September 26, 2018, 05:37:25 am »
What would ShowForeign be in terms of a GUI setting?

q.

SteveC

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Toggle Diagram Elements Programmatically
« Reply #4 on: October 02, 2018, 05:14:54 am »
I'm under the (possibly mistaken) impression that it is tied to the "Diagram>Properties>Diagram>Show namespace" toggle in the UI.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Toggle Diagram Elements Programmatically
« Reply #5 on: October 02, 2018, 09:24:49 pm »
This is stored in t_diagram.ShowForeign. Pretty mixed up, isn't it?

q.

SteveC

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Toggle Diagram Elements Programmatically
« Reply #6 on: October 03, 2018, 05:35:07 am »
Any idea how I might toggle this via the API and not try to upsert directly into the database?

The style string approach is a bit kludgey but cleaner than mixing API calls with SQL.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Toggle Diagram Elements Programmatically
« Reply #7 on: October 03, 2018, 06:04:51 am »
I guess you can't and need to go to the DB directly. Use Respository.Execute("your SQL") to do that. Try on a test DB first!

q.