Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: themiyac on June 03, 2015, 12:14:27 am

Title: Live Automation Changes
Post by: themiyac 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
Title: Re: Live Automation Changes
Post by: EXploringEA 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
Title: Re: Live Automation Changes
Post by: qwerty 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.
Title: Re: Live Automation Changes
Post by: Geert Bellekens 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().
Title: Re: Live Automation Changes
Post by: themiyac 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
Title: Re: Live Automation Changes
Post by: qwerty on June 04, 2015, 01:42:48 am
Now you did not add any element at all.

q.
Title: Re: Live Automation Changes
Post by: themiyac on June 04, 2015, 01:43:59 am
When I reload the project. My element appears in the project browser.
Title: Re: Live Automation Changes
Post by: themiyac 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!
Title: Re: Live Automation Changes
Post by: qwerty on June 04, 2015, 05:38:44 am
What method is GetElements?

q.
Title: Re: Live Automation Changes
Post by: Geert Bellekens 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
Title: Re: Live Automation Changes
Post by: Geert Bellekens 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#
Title: Re: Live Automation Changes
Post by: Aaron B 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.