Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Thyiad on February 26, 2014, 04:02:10 pm

Title: Why delete package cannot effective immediately ?
Post by: Thyiad on February 26, 2014, 04:02:10 pm
Well, i use the parentPackage.Packages delete it's one child package.
But it looks like not deleted. When click it , it pops:

Warning: Underlying model data may have been modified by another user. Press OK to refresh.

After delete child package, i had refresh and update the parent package. It's there some more is needed [ch65311]
Title: Re: Why delete package cannot effective immediatel
Post by: Aaron B on February 26, 2014, 04:24:33 pm
Try calling Repository.RefreshModelView to refresh the package contents in the Project Browser.
Title: Re: Why delete package cannot effective immediatel
Post by: Thyiad on February 26, 2014, 04:39:59 pm
Thank you very much. It works great!
Please allow me to ask one more question:
When i use EA.Element.TaggedValues.GetByName(name),
if the name doesn't in TaggedValues, it cause COMExeption.
It looks like that if EA.Collection have no right key, it will cause error.
Why ?
Title: Re: Why delete package cannot effective immediatel
Post by: Thyiad on February 26, 2014, 04:41:09 pm
Quote
Try calling Repository.RefreshModelView to refresh the package contents in the Project Browser.
Title: Re: Why delete package cannot effective immediatel
Post by: Aaron B on February 26, 2014, 04:58:20 pm
Quote
When i use EA.Element.TaggedValues.GetByName(name),
if the name doesn't in TaggedValues, it cause COMExeption.
It looks like that if EA.Collection have no right key, it will cause error.
Why ?

This is intentional and documented:
"If the collection does not contain any items, the method returns a null value. If the collection contains items, but it was unable to find an object with the specified name, the method raises an exception."
http://www.sparxsystems.com/enterprise_architect_user_guide/10/automation_and_scripting/collection.html

You need to add error handling to your code to catch the exception.  How exactly you do this depends on the programming language you are using.  E.g. For VBScript use On Error Resume Next, For JScript use a try...catch block.
Title: Re: Why delete package cannot effective immediatel
Post by: Thyiad on February 26, 2014, 05:54:39 pm
Quote
Quote
When i use EA.Element.TaggedValues.GetByName(name),
if the name doesn't in TaggedValues, it cause COMExeption.
It looks like that if EA.Collection have no right key, it will cause error.
Why ?

This is intentional and documented:
"If the collection does not contain any items, the method returns a null value. If the collection contains items, but it was unable to find an object with the specified name, the method raises an exception."
http://www.sparxsystems.com/enterprise_architect_user_guide/10/automation_and_scripting/collection.html

You need to add error handling to your code to catch the exception.  How exactly you do this depends on the programming language you are using.  E.g. For VBScript use On Error Resume Next, For JScript use a try...catch block.

It's useful and helped me. Thanks very much for your help.