Book a Demo

Author Topic: EA_OnPostNewDiagram on creating / copying diagram  (Read 2887 times)

Jenni

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
EA_OnPostNewDiagram on creating / copying diagram
« on: January 20, 2020, 11:34:07 pm »
Hello,

I have a function in my add-in (C#, EA version 12.0) that automatically inserts a diagram notes element in every newly created diagram. I am using the function EA_OnPostNewDiagram to get notified.

Now, when the user copies an existing diagram via project browser the function EA_OnPostNewDiagram is executed as well. Thus the new diagram contains two overlaying diagram notes elements. That's a problem for our QC.

While copying a diagram EA_OnPostNewDiagram is called before the diagram objects are inserted. So it is not possible to check whether the copied diagram already contains a diagram notes element.

How can I prevent the duplicate diagram notes? Is there a way to find out, whether the user is creating a new diagram or copying an existing one?

Thank you.
Jenni

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: EA_OnPostNewDiagram on creating / copying diagram
« Reply #1 on: January 21, 2020, 07:05:12 pm »
Hi Jenni, and welcome to the forum.


As far as I can tell I don't think there's a way to detect diagram copying as opposed to "from-scratch" creation.

Possibly you could move your note creation to EA_OnPostOpenDiagram or EA_OnPostCloseDiagram. While diagrams need not be automatically opened upon creation, you do need to open them to add things to them, which means that any note-less diagrams should be completely empty. Perhaps that's an acceptable limitation.

HTH,


/Uffe
My theories are always correct, just apply them to the right reality.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: EA_OnPostNewDiagram on creating / copying diagram
« Reply #2 on: January 21, 2020, 07:54:21 pm »
Why not lookup t_diagramobjects whether or not your note is already present?

q.
« Last Edit: January 21, 2020, 11:18:22 pm by qwerty »

Jenni

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: EA_OnPostNewDiagram on creating / copying diagram
« Reply #3 on: January 21, 2020, 09:48:44 pm »
Hi Uffe,

EA_OnPostOpenDiagram has the same problem. The new diagram is still empty when the event is fired.

But you gave me an idea: While copying a diagram OnPostNewDiagram is fired before OnPostOpenDiagram. While creating a new diagram from-scratch the events are fired in reverse order. So I start a timer in OnPostNewDiagram to suppress insertion the diagram notes element for one or two seconds. Thats not a perfect workaround, but it works.

Thanks for your suggestions.
Jenni