Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started 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
-
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
-
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.
-
And if all that doesn't work for you (for instance if you played with the treepos attribute of elements) then you can use
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().
-
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
-
Now you did not add any element at all.
q.
-
When I reload the project. My element appears in the project browser.
-
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!
-
What method is GetElements?
q.
-
What method is GetElements?
q.
That is just the Java equivalent to the property Package.Elements
Geert
-
Try this:
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#
-
I tried the ShowInProjectView() approach to just reload the Element in Project Browser but I am getting an exception.
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.