Book a Demo

Author Topic: JScript change diagram property : Use Alias if available  (Read 9236 times)

Pawel Zubkiewicz

  • EA User
  • **
  • Posts: 78
  • Karma: +2/-1
    • View Profile
    • zubkiewicz.com
JScript change diagram property : Use Alias if available
« on: July 13, 2016, 07:02:00 pm »
Hi All :-)

Do you know if it's possible to change diagram property: Use Alias if available from a (J)Script?
If yes, how?
Enhanced Requirement Attributes Addin for Enterprise Architect (ERA Addin) - http://zubkiewicz.com/?p=239

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: JScript change diagram property : Use Alias if available
« Reply #1 on: July 13, 2016, 07:25:56 pm »
I'm not sure if that property is exposed in the API (probably not).
If not then there's a good chance it is stored in the StyleEx property of the diagram (which is exposed IIRC)

Geert

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: JScript change diagram property : Use Alias if available
« Reply #2 on: July 13, 2016, 07:29:16 pm »
Hi Pawel,


Yes. It and a bunch of other settings are stored in t_diagram.PDATA, which is mirrorred in Diagram.ExtendedStyle -- not to be confused with Diagram.StyleEx, which is stored in t_diagram.StyleEx.

The format is a string with a bunch of semicolon-separated key=value pairs. So all you need to do is replace UseAlias=0 with UseAlias=1 in t_diagram.ExtendedStyle.


/Uffe
My theories are always correct, just apply them to the right reality.

Pawel Zubkiewicz

  • EA User
  • **
  • Posts: 78
  • Karma: +2/-1
    • View Profile
    • zubkiewicz.com
Enhanced Requirement Attributes Addin for Enterprise Architect (ERA Addin) - http://zubkiewicz.com/?p=239

Pawel Zubkiewicz

  • EA User
  • **
  • Posts: 78
  • Karma: +2/-1
    • View Profile
    • zubkiewicz.com
Re: JScript change diagram property : Use Alias if available
« Reply #4 on: July 13, 2016, 07:54:42 pm »
Is it possible to edit this from JScript level?

When I want to see in JScritp values of diagram.ExtendedStyle or diagram.StyleEx I get empty string.
Enhanced Requirement Attributes Addin for Enterprise Architect (ERA Addin) - http://zubkiewicz.com/?p=239

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: JScript change diagram property : Use Alias if available
« Reply #5 on: July 13, 2016, 08:17:30 pm »
As Uffe mentioned it is stored in t_diagram.PDATA with UseAlias. This is not exposed in the API. You will need Repository.SQLQuery to read and Repository.Execute to update that value.

q.

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: JScript change diagram property : Use Alias if available
« Reply #6 on: July 13, 2016, 08:39:38 pm »
No, it is accessible through the API, as per my first post.

If there's nothing in the string just add what you need. But if you're creating the diagram through the API as well, it's a good idea to .Update() it in between. This gives EA the chance to set any default values in both columns / attributes.

/U
My theories are always correct, just apply them to the right reality.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: JScript change diagram property : Use Alias if available
« Reply #7 on: July 13, 2016, 09:15:57 pm »
Hu  :-[ I should have had a cup of coffee before posting. Indeed PDATA is ExtendedStyle (of course for other objects PDATA maps to MiscData; but well, it's EA).

q.

Pawel Zubkiewicz

  • EA User
  • **
  • Posts: 78
  • Karma: +2/-1
    • View Profile
    • zubkiewicz.com
Re: JScript change diagram property : Use Alias if available
« Reply #8 on: July 13, 2016, 10:08:51 pm »
Thanks for help. I found out that I couldn't see that data during creation of diagram by script even with Update() method.

Code: [Select]
...
var diagram as EA.Diagram
diagram = subPackage.Diagrams.AddNew(issueNumber, "Maintenance")
diagram.Notes = "Test diagram created by the ManageDiagramsExample script"
diagram.Update();

diagramProperties(diagram.DiagramID);
...
where  diagramProperties is defined as:
Code: [Select]
function diagramProperties(diagramID)
{
var diagram as EA.Diagram;
diagram = Repository.GetDiagramByID(diagramID);

Session.Output("Diagram id      = "+diagramID);
Session.Output("Diagram name    = "+diagram.Name);
Session.Output("Diagram PDATA   = "+diagram.ExtendedStyle);
Session.Output("Diagram StyleEX = "+diagram.StyleEx);

}

and this is what I get as output:
Code: [Select]
Diagram id      = 116
Diagram name    = testDiagram
Diagram PDATA   =
Diagram StyleEX =

When I call diagramProperties() function on any diagram it displays all information. It's like diagram.ExtendedStyle and diagram.StyleEx are not persisted in db until JScript is finished. But updated is called, and Diagram Name is saved.

Does anyone have any idea what I'm doing wrong?
Enhanced Requirement Attributes Addin for Enterprise Architect (ERA Addin) - http://zubkiewicz.com/?p=239

Pawel Zubkiewicz

  • EA User
  • **
  • Posts: 78
  • Karma: +2/-1
    • View Profile
    • zubkiewicz.com
Re: JScript change diagram property : Use Alias if available
« Reply #9 on: July 13, 2016, 10:15:13 pm »
Alright, I cannot read during creation of diagram but I can save into it :-)
Code: [Select]
diagram.ExtendedStyle ="HideRel=0;ShowTags=0;ShowReqs=0;ShowCons=0;OpParams=1;ShowSN=0;ScalePI=0;PPgs.cx=2;PPgs.cy=1;PSize=1;ShowIcons=1;SuppCN=0;HideProps=0;HideParents=0;UseAlias=1;HideAtts=0;HideOps=0;HideStereo=0;HideEStereo=0;FormName=;";
diagram.Update();

It works ;-)
Enhanced Requirement Attributes Addin for Enterprise Architect (ERA Addin) - http://zubkiewicz.com/?p=239

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: JScript change diagram property : Use Alias if available
« Reply #10 on: July 14, 2016, 01:07:04 am »
Hi again,


I think the problem there is that when creating an entity, EA doesn't set certain properties (in this case .ExtendedStyle) until the entity is written to the database -- but the object in your code is not automatically updated with those properties. By contrast, the name was specified by you when you created the Diagram object so that information is read from the object and written down.

Try Refresh()ing the diagram collection after Update()ing the diagram, then retrieving the new diagram from the refreshed collection. That should provide you with a fresh object containing all the data EA has stored in the database.


/Uffe
My theories are always correct, just apply them to the right reality.