Author Topic: Live Automation Changes  (Read 6934 times)

themiyac

  • EA User
  • **
  • Posts: 26
  • Karma: +0/-0
    • View Profile
Live Automation Changes
« on: June 03, 2015, 12:14:27 am »
I am dabbling in creating blocks and packages in EA using the API.

myElement.Update();
myPackage.GetElements().Refresh();

The above implemented Update() and Refresh() methods will add the block to the EA file, but I must close the project and reopen the file manually for these changes to be reflected in the project. Is there a built in feature that can refresh the project to reflect these changes without having to close and reopen the file.
Thanks

EXploringEA

  • EA User
  • **
  • Posts: 172
  • Karma: +8/-0
    • View Profile
Re: Live Automation Changes
« Reply #1 on: June 03, 2015, 02:17:58 am »
If I understand the question you use a repository method

- Repository.AdviseElementChange(myelement.ElementID)

Worth checking out the other Repository methods that are available following changes e.g. RefreshModelView, RefreshOpenDiagrams
« Last Edit: June 03, 2015, 02:25:07 am by MrWappy »
EXploringEA - information, utilities and addins

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Live Automation Changes
« Reply #2 on: June 03, 2015, 03:44:59 am »
Try Repository.ReloadDiagram if it does not appear directly on your diagram. Else you should explain what "reflect these changes"  does mean to you.

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Live Automation Changes
« Reply #3 on: June 03, 2015, 01:21:09 pm »
And if all that doesn't work for you (for instance if you played with the treepos attribute of elements) then you can use
Code: [Select]
RefreshModelView (long PackageID) with or without packageID.

Geert

PS. The Refresh() operation is only needed to reload the elements in the collection you have used to add or delete and element. You only need this if you are going to loop that same collection further in the code. In most cases you don't need to call Refresh().

themiyac

  • EA User
  • **
  • Posts: 26
  • Karma: +0/-0
    • View Profile
Re: Live Automation Changes
« Reply #4 on: June 04, 2015, 01:03:38 am »
public void AddElement(String packageName, String inputName, String elementType){
            org.sparx.Package model = r.GetModels().GetAt((short)0);
            org.sparx.Package myPackage = model.GetPackages().GetByName(packageName);
            org.sparx.Element myElement = myPackage.GetElements().AddNew(inputName, elementType);
            //myElement.Update();
            //myPackage.GetElements().Refresh();
            r.RefreshModelView(0);
      }
I tried the RefreshModelView() method and my Project Browser still doesn't reflect the changes until I reload the project. Any suggestions?
Thanks

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Live Automation Changes
« Reply #5 on: June 04, 2015, 01:42:48 am »
Now you did not add any element at all.

q.

themiyac

  • EA User
  • **
  • Posts: 26
  • Karma: +0/-0
    • View Profile
Re: Live Automation Changes
« Reply #6 on: June 04, 2015, 01:43:59 am »
When I reload the project. My element appears in the project browser.

themiyac

  • EA User
  • **
  • Posts: 26
  • Karma: +0/-0
    • View Profile
Re: Live Automation Changes
« Reply #7 on: June 04, 2015, 02:46:28 am »
public void AddElement(String packageName, String inputName, String elementType){
            org.sparx.Package model = r.GetModels().GetAt((short)0);
            org.sparx.Package myPackage = model.GetPackages().GetByName(packageName);
            org.sparx.Element myElement = myPackage.GetElements().AddNew(inputName, elementType);
            myElement.Update();
            myPackage.GetElements().Refresh();
            org.sparx.Element newElement = myPackage.GetElements().GetByName(inputName);
            r.ShowInProjectView(newElement);
      }

I tried the ShowInProjectView() approach to just reload the Element in Project Browser but I am getting an exception.

Exception in thread "main" java.lang.UnsupportedOperationException
      at org.sparx.Repository.ShowInProjectView(Repository.java:1089)
      at EAAdd.AddElement(EAAdd.java:31)
      at EAAdd.main(EAAdd.java:47)

I checked the type of newElement by using newElement.GetObjectType() and it is of element type and ShowInProjectView() says it supports this type in documentation.

Help please!
Thanks!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Live Automation Changes
« Reply #8 on: June 04, 2015, 05:38:44 am »
What method is GetElements?

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Live Automation Changes
« Reply #9 on: June 04, 2015, 01:07:03 pm »
Quote
What method is GetElements?

q.
That is just the Java equivalent to the property Package.Elements

Geert

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Live Automation Changes
« Reply #10 on: June 04, 2015, 01:15:03 pm »
Try this:
Code: [Select]
public void AddElement(String packageName, String inputName, String elementType){
           org.sparx.Package model = r.GetModels().GetAt((short)0);
           org.sparx.Package myPackage = model.GetPackages().GetByName(packageName);
           org.sparx.Element myElement = myPackage.GetElements().AddNew(inputName, elementType);
           myElement.Update();
           //myPackage.GetElements().Refresh();
           r.RefreshModelView(myPackage.PackageID);
     }
(or is that myPackage.GetPackageID() as well in Java?)

I'm not sure why you get the error in ShowInProjectView().

Geert

PS. Is there any reason you insist on making your life difficult by using Java with EA? If not then I suggest you switch over to C#

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Live Automation Changes
« Reply #11 on: June 05, 2015, 09:47:13 am »
Quote
I tried the ShowInProjectView() approach to just reload the Element in Project Browser but I am getting an exception.
Quote
I'm not sure why you get the error in ShowInProjectView().

Calling ShowInProjectView via the Java API unfortunately throws an exception in EA 12 at the moment.  This is a known issue which we hope to correct in a future update.