Author Topic: Add Element to Diagram via Add-In  (Read 931 times)

A. Engle

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Add Element to Diagram via Add-In
« on: August 16, 2014, 02:24:13 am »
I'm creating a model (package), a package within that model, a diagram within that package and elements within THAT package all with my C# based add-in.  I'm obviously executing the right Updates and Refreshes.  I'm even able to get tagged values on the element, as well as create a scenario on the element and steps on the scenario.

But I cannot get the element on to the Diagram to save my life! I also can't find any (up-to-date/relevant/c# based) examples online.

When I open the .eap file after my add-in completes and open the diagram, it's blank/empty/barren of all elements.

So what is the process?


A. Engle
TOGAF 9.1

qwerty

  • EA Guru
  • *****
  • Posts: 9667
  • Karma: +176/-150
  • I'm no guru at all
    • View Profile
Re: Add Element to Diagram via Add-In
« Reply #1 on: August 16, 2014, 03:20:49 am »
You need to create DiagramObjects for the desired diagram. Once created you need to link the objectId. From my Scripting book:

Code: [Select]
dia_obj = diagram.DiagramObjects.AddNew ("l=10;r=110;t=-20;b=-80", "");
  dia_obj.ElementID = element.ElementID;
  dia_obj.Update ();
  Repository.ReloadDiagram (diagram.PackageID);

q.

A. Engle

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Add Element to Diagram via Add-In
« Reply #2 on: August 16, 2014, 03:52:34 am »
AHA!  Linking the DO to the Element...that makes sense!

Do I need to do the ReloadDiagram?  I'm currently doing:  diagram.DiagramObjects.Refresh() and diagram.Update()?

which is the 'more preferred' method or is there a reason for one or the other?

Thanks qwerty!  glad I could give you another opportunity to plug yer book!   ;)

A. Engle
TOGAF 9.1

qwerty

  • EA Guru
  • *****
  • Posts: 9667
  • Karma: +176/-150
  • I'm no guru at all
    • View Profile
Re: Add Element to Diagram via Add-In
« Reply #3 on: August 16, 2014, 06:26:15 am »
lol

The Update is to finalize the creation. So you don't need diagram.update as the diagram is already there. The Refresh is only needed if you want to iterate the collection afterwards which is usually not the case (you just created the objects and know about them). The Reload finally will trigger EA to draw the diagram anew. EA is laze (for a good reason) and only when you're done updating you call it once to give the user a fresh view.

q.

A. Engle

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Add Element to Diagram via Add-In
« Reply #4 on: August 18, 2014, 10:23:41 pm »
Works like a charm.  Thanks again!

A. Engle
TOGAF 9.1