Author Topic: Deep Delete element  (Read 7580 times)

Danny F

  • EA User
  • **
  • Posts: 60
  • Karma: +0/-0
    • View Profile
Deep Delete element
« on: December 11, 2012, 01:37:10 am »
Hi

How can I react to a delete action on a diagram element (linked)

I want to delete it also from the model (as if the delete action was done on the element in the project browser)

for example deleting a connector on a diagram asks me if I want to delete it from the model or not.



Thanks

« Last Edit: December 11, 2012, 02:15:06 am by dannyf »
Reg.

Danny

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Deep Delete element
« Reply #1 on: December 11, 2012, 02:54:07 am »
Ctrl-Del

q.

Danny F

  • EA User
  • **
  • Posts: 60
  • Karma: +0/-0
    • View Profile
Re: Deep Delete element
« Reply #2 on: December 11, 2012, 05:25:25 pm »
Thanks - but I want to react when the user doesn't use Ctrl-Del

Reg.

Danny

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: Deep Delete element
« Reply #3 on: December 11, 2012, 06:11:48 pm »
When you delete a diagram object the event 'EA_OnPreDeleteDiagramObject' fires passing the ID of the element that the diagramobject links to.

First check if you want to delete the element from the model behind the diagramobject, and if so delete it from the model and pass 'truefalse' to EA to prevent EA from trying to delete the (at that time already deleted) diagramobject.

Here's some (vbscript) code that deletes an element (and consequently, its associated diagramobjects) from the model:

Code: [Select]
sub DeleteElementFromModel(elt)            
      dim elements, i
      if elt.ParentID = 0 then
            set elements = GetPackageByID(elt.PackageID).elements
      else
            set elements = GetElementByID(elt.ParentID).elements
      end if

      for i = 0 to elements.Count - 1
            if elements.GetAt(i).ElementID = elt.ElementID then
                  elements.DeleteAt i, false
                  Elements.Refresh()
                  exit sub
            end if
      next
end sub

best regards,

Paulus
« Last Edit: December 11, 2012, 08:27:57 pm by pmaessen »

Danny F

  • EA User
  • **
  • Posts: 60
  • Karma: +0/-0
    • View Profile
Re: Deep Delete element
« Reply #4 on: December 11, 2012, 06:57:24 pm »
thanks,  WORKS  :)

This method is not documented in the SDK !  :o (enterprise_architect_sdk.pdf)

I checked the application help (enterprise architect user guide) and there it is included ! in the automation chapter (I'm gonna use that resource now   ::) )

thanks again


gr
Reg.

Danny

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Deep Delete element
« Reply #5 on: December 11, 2012, 07:22:07 pm »
Danny,

I didn't even know that pdf existed.
Anyway, you should indeed just use the help file.

Geert

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: Deep Delete element
« Reply #6 on: December 11, 2012, 08:29:01 pm »
ur welcome!

Btw i made a mistake, you should pass FALSE to EA to prevent deletion. Update the previous post for future reference

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8085
  • Karma: +118/-20
    • View Profile
Re: Deep Delete element
« Reply #7 on: December 12, 2012, 08:45:09 am »
Please... Don't do that.

  • This message is fired before the actual delete happens. There may be things that would prevent the delete.
  • Undo is still a possibility when removing elements from a diagram. But not with that code.
  • There is no prompt for this action and no way to undo elements accidentally removed from the model completely.
  • Anyone who understand how to use EA (or has looked at the manual) will end up completely deleting elements when they are intending to remove them off the diagram.
I wouldn't be surprised if there aren't more (very good) reasons why this is a bad idea. But I can't imagine a single good reason for doing it. I can see not wanting to train people to use Ctrl delete, but that's not a good reason.

PS. The SDK document was produced for a very short period of time when we tried moving that information from the help file. It is very much out of date, with the information now being back in the help file.
« Last Edit: December 12, 2012, 08:46:24 am by simonm »

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: Deep Delete element
« Reply #8 on: December 12, 2012, 10:02:43 am »
Hi Simon,

You are of course absolutely right that you need to understand the consequences of what you are doing before scripting something like this and that there aretrade-offs to be considered.

But in as far as  end-users are concerned i think it is not unreasonable to ask for an automatic removal of a model element that (from a user perspective) belongs to only that specific diagram.

For the record the actual script i use includes a 'sanity check' on the element prior to the call to the delete script i provided: only elements that an end-user would consider to be private to the diagram (eg activityinitial, action, ...) are eligible  for removal from the model as well, and even then they are only removed if the element actually is an orphan from the model point of view.

To me preventing cluttering of the model with orphaned elements outweighs the disadvantage of not being able to undo the delete of elements if they can easily be re-introduced.

So no i don't consider this a bad idea at all, as long as you think it through. You mention that there may be additional advantages, could you clarify on that? So far i haven't encountered any. Can it be that the internals of EA may hold a surprise for me?

best regards,

Paulus
« Last Edit: December 12, 2012, 10:05:12 am by pmaessen »

Danny F

  • EA User
  • **
  • Posts: 60
  • Karma: +0/-0
    • View Profile
Re: Deep Delete element
« Reply #9 on: December 12, 2012, 06:17:22 pm »
Thanks very much for the replies and warning !

The use I have for it is very specific for an Add-in
It is not a general 'Ctrl-D' replacement

It concerns an Add-in which has specific diagrams for specific stereotyped elements.
It's only for those elements, which can only be added to specific diagrams, that I want the functionality.

I'm very much a newbie concerning EA Add-in development, any help is very much appreciated  :)
gr

Reg.

Danny

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: Deep Delete element
« Reply #10 on: December 12, 2012, 07:13:34 pm »
Exactly what i'm using it!  :)

But be aware: inexperienced users or others not using your add-in -may- re-use an element in other diagrams anyway (you can always drag it to another diagram from the project explorer).

So be sure to check if the element is used exclusively by a diagram before deleting it.

grts,

Paulus

SvenK

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Deep Delete element
« Reply #11 on: January 09, 2013, 12:54:03 am »
Quote
Btw i made a mistake, you should pass FALSE to EA to prevent deletion. Update the previous post for future reference

What is the reason for passing False?
In
http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/collection.htm
it is written that the Boolean in DeletAt() is unused.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Deep Delete element
« Reply #12 on: January 09, 2013, 03:37:15 am »
You can pass any value. False == one of any value.

q.
« Last Edit: January 09, 2013, 03:40:21 am by qwerty »

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: Deep Delete element
« Reply #13 on: January 09, 2013, 05:05:19 am »
Hi SvenK,

I wasn't referring to the 2nd argument in 'DeleteAt' but to the return value of the event 'EA_OnPreDeleteDiagramObject'.

You need to pass FALSE to stop EA from deleting the object as well if your code handles the deletion.

Effectively this is (mis)using an event intended to -prevent- the deletion of an ob ject to actually -handle- the deletion ourselves... but it works.

grts,

Paulus
« Last Edit: January 09, 2013, 05:06:10 am by pmaessen »