Book a Demo

Author Topic: Element update & related things - when to use & why  (Read 9319 times)

Mr Stuff

  • EA User
  • **
  • Posts: 64
  • Karma: +0/-0
    • View Profile
Element update & related things - when to use & why
« on: June 22, 2017, 08:12:45 pm »
Being new to EA scripting I am still unclear/confused about the various things that need to be updated when scripting changes.

For example I see, variously

Code: [Select]
element.Update

Code: [Select]
element.Update
Repository.AdviseElementChange(element.ElementID)

Code: [Select]
diagram.Update

When do I need to update things, "AdviseElementChange" save diagram etc. and in what order, etc. when operating on diagram elements and elements? What other "refresh", "update" etc. methods are there?

Thanks

Julian

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Element update & related things - when to use & why
« Reply #1 on: June 22, 2017, 10:24:46 pm »
Update() in general will save the changes you are making to objects in memory to the database.
In general (there are exceptions) if you don't call update() nothing will be changed in the database.

AdviseElementChange() will tell the GUI that yo made a change to a particular object, allowing the GUI to update its's cached version of that element.

Refresh() is only needed when you want to reload collections from the database into your API object.

Geert

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Element update & related things - when to use & why
« Reply #2 on: June 22, 2017, 10:32:49 pm »
Hi Julian,

*.Update() writes the object to the database. If you don't call that after making changes to an Element, Package, Attribute, Collection, etc, the changes will be lost when the variable goes out of scope.

Collection.Refresh() does the opposite: it rereads the collection's contents from the database, so the Collection object in your code is in sync. It should be called after you've added or deleted objects in a Collection. You don't need to call it if you've only made changes to the objects in the collection -- I think.

With diagrams, you should call Diagram.Update() after modifying the diagram's attributes or its contents.

Those are the key ones. You need to use them, or your changes won't take.

Element etc also have a .Refresh(), but it doesn't do the same thing as Collection.Refresh(). Instead, it updates the GUI. You can typically leave that out, I usually do. If needed, the client will flash a message telling the user to refresh manually, so it tends to take care of itself.

Repository.Advise*Change() tells the EA client to refresh the GUI, if necessary, after you've made changes (to already existing objects) in the database. If it works right, it should advise all currently connected clients but I'm not sure about that.

Project.ReloadProject() reloads the current project, and Repository.RefreshModelView() reloads a package. But, I'm pretty sure, only for the client where the call is issued.

Repository.RefreshOpenDiagrams() and Repository.ReloadDiagram() refresh diagrams if they're open (again, only in the client where the call is issued).

HTH,


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

Mr Stuff

  • EA User
  • **
  • Posts: 64
  • Karma: +0/-0
    • View Profile
Re: Element update & related things - when to use & why
« Reply #3 on: June 23, 2017, 12:32:48 am »
Thank you Geert & Uffe - that's just what I needed to know - confirmed a few things I had worked out but also added useful some new info (80:20 in your collective favour ;)

Great!

Mr Stuff

  • EA User
  • **
  • Posts: 64
  • Karma: +0/-0
    • View Profile
Re: Element update & related things - when to use & why
« Reply #4 on: June 23, 2017, 04:05:01 pm »
Ah... one more thing!

Scenario: I select a diagram element, find the model element, change its type and perform element.update - but the content of the element properties pane does not update until I deselect and reselect it... is that what I need AdviseElementChange()? I also have the issue that when I change an element type from e.g. Action to Activity and then - after element.update - try to modify the tagged values of the Activity the tagged values have not (yet?) been created or become accessible... is that the same issue?

Thanks

Julian

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Element update & related things - when to use & why
« Reply #5 on: June 23, 2017, 05:56:09 pm »
No. This is an ignored EA issue. You might call Repository.ShowInProjectView to overcome the situation. That however might toggle the current browser folding.

q.

Mr Stuff

  • EA User
  • **
  • Posts: 64
  • Karma: +0/-0
    • View Profile
Re: Element update & related things - when to use & why
« Reply #6 on: June 23, 2017, 08:33:29 pm »
Sorry - can you clarify? I couldn't connect the answers to the sub-questions

BTW Fixed the TV access - I may have overlooked the need to update the tagged value object; that bit is working now.

Thanks

Julian

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Element update & related things - when to use & why
« Reply #7 on: June 23, 2017, 08:55:48 pm »
An Update does not seem to be reflect in the docked properties window (that was your observation; and somehow I have in mind that I observed that too but I already got used to such kind of nuisances). So that's one of those EA flaws (still; I guess). It might work that you send Repository.ShowInProjectView which will re-select the element and thereby updating the docked properties. Though this might alter the folding of the current browser tree too.

q.

Mr Stuff

  • EA User
  • **
  • Posts: 64
  • Karma: +0/-0
    • View Profile
Re: Element update & related things - when to use & why
« Reply #8 on: June 23, 2017, 09:19:08 pm »
Ok, got it. Thx!