Book a Demo

Author Topic: Updating Diagram.StyleEx attribute  (Read 10974 times)

tzafrir

  • EA User
  • **
  • Posts: 127
  • Karma: +0/-0
    • View Profile
Updating Diagram.StyleEx attribute
« on: July 03, 2016, 01:19:55 am »
Hi,

I am updating StyleEx variable with new data. (i.e. modifying its one of the ; separated variables, the MDGDgm one, with a new value) and updating the diagram with this new string:

currentDiagram.StyleEx = newStyleEx.

after that I am doing
currentDiagram.Update().

I have noticed that the variable is not getting updated.
Is this a read only variable that can not be modified?
or there is another way to have the diagram updated with the newStyleEx value.

Tzafrir







qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Updating Diagram.StyleEx attribute
« Reply #1 on: July 03, 2016, 07:42:05 pm »
I had no problem changing the StyleEx. Maybe you would also need to change the Type correctly. This is a r/o attribute and you can change that only with a SQL.

q.

tzafrir

  • EA User
  • **
  • Posts: 127
  • Karma: +0/-0
    • View Profile
Re: Updating Diagram.StyleEx attribute
« Reply #2 on: July 04, 2016, 03:06:43 pm »
Ok,

Can you tell me what SQL API you are using to perform an update?
repository.SQLQuery(sql);
throws on exception for missing a "Select" keyword

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Updating Diagram.StyleEx attribute
« Reply #3 on: July 04, 2016, 04:53:29 pm »
SQLquery is, as the name says, for queries. Use Repository.Execute(anySql) to reach the DB directly. This is an undocumented but well functioning method and your last resort in cases like this.

q.

rwittmann

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: Updating Diagram.StyleEx attribute
« Reply #4 on: September 19, 2018, 12:51:58 am »
I know, this is quite an old topic, but I came to this point this week.
I cannot change the StyleEx in an SQL-Update-statement in a script if the diagram has not yet been touched inside EA before.

"has not yet been touched inside EA before" should express: I generate the diagrams also from a (different) script.


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Updating Diagram.StyleEx attribute
« Reply #5 on: September 19, 2018, 01:48:37 am »
I know, this is quite an old topic, but I came to this point this week.
I cannot change the StyleEx in an SQL-Update-statement in a script if the diagram has not yet been touched inside EA before.

"has not yet been touched inside EA before" should express: I generate the diagrams also from a (different) script.

You're going to have to explain in a bit more detail to get any concrete help I'm afraid.

Geert

rwittmann

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: Updating Diagram.StyleEx attribute
« Reply #6 on: September 19, 2018, 08:12:41 pm »
Yes, Geert, you are absolutely right:

I'll try to describe my sequence a bit more detailed:
I have a python script running which generates requirement diagrams containing various elements
The generation works, the diagrams are created, containing the elements.

Now I run a different script (from inside EA), in which I try to modify the displayed compartments (I want to have the notes of each element shown).
I've read that I have to achieve this by changing the extended style via a SQL query.
So I read out the extended style from another diagram where the notes are shown.
Now I execute the script on a diagram where the extended style only contains the info on the extended diagram style (MDGDgm=Extended::Requirements;).
Result: extended style is not updated (even though diagram is updated through script and package is reloaded and even EA is restartet).

Now, I execute the script on a diagram where I just open the diagram properties, don't change anything, just close the properties with the "OK" button.
Result of the properties action: extended style is changed, notes are not shown by default.
Result of the script execution: extended style is changed to show the notes, diagram displays the notes of each element as well...

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Updating Diagram.StyleEx attribute
« Reply #7 on: September 19, 2018, 08:22:38 pm »
Result: extended style is not updated (even though diagram is updated through script and package is reloaded and even EA is restartet).

Can't be sure without seeing your script code, but saving the diagram in the script might very well undo the previous setting of the StyleEx field.

If you post the actual script we might be able the spot the problem.

Geert

rwittmann

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: Updating Diagram.StyleEx attribute
« Reply #8 on: September 19, 2018, 10:21:12 pm »
Thanks, Geert!
You are right!

The following does not work. The Update() methods seem to revert the SQL update:
Code: [Select]
!INC Local Scripts.EAConstants-JScript

OnProjectBrowserScript();

function OnProjectBrowserScript()
{
// Get the type of element selected in the Project Browser
var treeSelectedType = Repository.GetTreeSelectedItemType();

if (treeSelectedType == otDiagram)
{
var theDiagram as EA.Diagram;
var package as EA.Package;
var diaId;
var name;
theDiagram = Repository.GetTreeSelectedObject();
diaId = theDiagram.DiagramID;
package = Repository.GetPackageByID(theDiagram.PackageID);
Repository.Execute("UPDATE t_diagram set StyleEx='ExcludeRTF=0;DocAll=0;HideQuals=0;AttPkg=1;ShowTests=0;ShowMaint=0;SuppressFOC=1;MatrixActive=0;SwimlanesActive=1;KanbanActive=0;MatrixLineWidth=1;MatrixLineClr=0;MatrixLocked=0;TConnectorNotation=UML 2.1;TExplicitNavigability=0;AdvancedElementProps=1;AdvancedFeatureProps=1;AdvancedConnectorProps=1;m_bElementClassifier=1;ProfileData=;MDGDgm=Extended::Requirements;STBLDgm=;ShowNotes=1;VisibleAttributeDetail=0;ShowOpRetType=1;SuppressBrackets=0;SuppConnectorLabels=0;PrintPageHeadFoot=0;ShowAsList=0;SuppressedCompartments=;Theme=:119;SaveTag=5AB66EC4;' where Diagram_ID=" + diaId + ";");
theDiagram.Update();
package.Update();
return;
}
else
{
// Error message
Session.Prompt( "This script does not support items of this type.", promptOK );
}
}

It works if I replace the Update() methods with
Code: [Select]

Repository.SaveAllDiagrams();

Thanks again!
Rene


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Updating Diagram.StyleEx attribute
« Reply #9 on: September 19, 2018, 10:57:37 pm »
The culprit is
Code: [Select]
Repository.Execute("UPDATE t_diagram set ...");
theDiagram.Update();

The Update undoes the previous Execute. Swap both and you should be done.

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Updating Diagram.StyleEx attribute
« Reply #10 on: September 19, 2018, 11:11:32 pm »
As far as I can see there is nothing to update at all.
Unless there is code we aren't seeing here.
You might want to do a reload of the diagram however to make the changes visible.

Geert

rwittmann

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: Updating Diagram.StyleEx attribute
« Reply #11 on: September 21, 2018, 12:09:31 am »
No, there is no additional code here.

My assumption was that I need to call the Update method in order to write it into the repository (similar to a SQL commit).

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Updating Diagram.StyleEx attribute
« Reply #12 on: September 21, 2018, 01:42:39 am »
No, there is no additional code here.

My assumption was that I need to call the Update method in order to write it into the repository (similar to a SQL commit).

No, the Update() operations are there to save the state of the API object to the database.
Using Repository.Execute bypasses the whole API and writes directly in the database (with immediate commit)

Geert