Author Topic: Remove elements in script  (Read 7344 times)

bITs.EA

  • EA User
  • **
  • Posts: 80
  • Karma: +2/-0
    • View Profile
Remove elements in script
« 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


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Remove elements in script
« Reply #1 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.
« Last Edit: October 17, 2013, 02:33:48 am by qwerty »

bITs.EA

  • EA User
  • **
  • Posts: 80
  • Karma: +2/-0
    • View Profile
Re: Remove elements in script
« Reply #2 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...

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Remove elements in script
« Reply #3 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.

bITs.EA

  • EA User
  • **
  • Posts: 80
  • Karma: +2/-0
    • View Profile
Re: Remove elements in script
« Reply #4 on: October 17, 2013, 11:40:49 pm »
Yeah I was afraid this would be the only solution...

Thanks for the info.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Remove elements in script
« Reply #5 on: October 18, 2013, 04:49:49 pm »
What I do in my tooling 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

bITs.EA

  • EA User
  • **
  • Posts: 80
  • Karma: +2/-0
    • View Profile
Re: Remove elements in script
« Reply #6 on: November 01, 2013, 01:39:35 am »
Thanks for the info, Geert. I will have a look at this solution :)