Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: bITs.EA on October 17, 2013, 01:31:49 am

Title: Remove elements in script
Post by: bITs.EA on October 17, 2013, 01:31:49 am
Hi

I think this will be a simple question: How can I delete an element via scripting? I don't see a delete-method in the element class in the references found in the EA user guide.

I have an sql which selects several elements (only the object_id is listed in the sql) in different packages. So I want to loop through all the object_ids from the sql (easy loop) and just use some method like element.getByID(id).delete.

Is there a (undocumented) method like this??

Grts

Title: Re: Remove elements in script
Post by: qwerty on October 17, 2013, 02:30:26 am
There are Delete and DeleteAt methods for the collections which contain the elements. So you need to get the collection from the according parent.

You "could" do Repository.Execute ("DELETE FROM...") but I would not really recommend that.

q.
Title: Re: Remove elements in script
Post by: bITs.EA on October 17, 2013, 06:00:41 pm
Can I make a collection from an sql? Because those elements I want to delete are all from different packages...

Deleting it via repository.execute is my last option, because then I would have to delete all the links in other tables too...
Title: Re: Remove elements in script
Post by: qwerty on October 17, 2013, 08:20:32 pm
No. You have to get the parent package and retrieve the element in its elements collection.

I'd say that it's a design flaw that all objects miss a delete method. But I gave up hope being able to influence EA's design by sending in feature requests. That worked back in 2003 for say 3 years. But then it did not make sense any more. I even do not put much hope in sending bug reports. Some get still fixed. But my list of open bugs is still large. And probably it would even grow if I'd send all bugs I know about.

q.
Title: Re: Remove elements in script
Post by: bITs.EA on October 17, 2013, 11:40:49 pm
Yeah I was afraid this would be the only solution...

Thanks for the info.
Title: Re: Remove elements in script
Post by: Geert Bellekens on October 18, 2013, 04:49:49 pm
What I do in my tooling framework (https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework) is write wrapper classes for all the EA classes in the API.
On such a wrapper class you can write a delete() operation and implement is such that it first retrieves the owner and then deletes itself from the owners .Elements collection.

In my add-ins and tools I only use the wrapper classes, not the actual API classes. That sort of shields me from most of the madness ;D

Geert
Title: Re: Remove elements in script
Post by: bITs.EA on November 01, 2013, 01:39:35 am
Thanks for the info, Geert. I will have a look at this solution :)