Author Topic: Add diagram notes from script  (Read 7536 times)

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Add diagram notes from script
« on: July 04, 2012, 07:07:43 am »
Hi,

I'm trying to add a diagram note to a diagram using vbscript, but i  can't get it tow work.

I tried doing this as follows:

Quote
dim dgmObject as EA.DiagramObject
dim dgmElement as EA.Element

' Create element on the diagram parent
set dgmElement = ucActivity.Elements.AddNew("","DiagramNotes ")

' Add the element to the diagram
set dgmObject = ucDgm.diagramObjects.AddNew( "l=4;t=8;r=100;b=100;", "" )
dgmObject.ElementID( dgmElement.ElementID )
dgmObject.Update()

But i get an error 'invalid type'. Replacing 'DiagramNotes ' with 'Notes' removes the error and adds a (empty) note to the diagram as expected.

What am i doing wrong, is 'DiagramNotes' not the correct type? Or should diagramnotes be added in another way?

regards,

Paulus

« Last Edit: July 04, 2012, 07:10:22 am by pmaessen »

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Add diagram notes from script
« Reply #1 on: July 04, 2012, 03:16:21 pm »
Hi Paulus,

I attach an example in C#. It works and I use this snippet to attach a linked note to a diagram object.

                        EA.Element el = (EA.Element)Repository.GetContextObject();
                        EA.Package pkg = Repository.GetPackageByID(el.PackageID);
                        if (pkg.IsProtected || dia.IsLocked || el.Locked || dia == null) break;

                        // save diagram
                        Repository.SaveDiagram(dia.DiagramID);
                        
                        EA.Element elNote = null;
                        try
                        {
                            elNote = pkg.Elements.AddNew("", "Note");
                            elNote.Update();
                            pkg.Update();
                        }
                        catch { break; }

                        // add element to diagram
                        // "l=200;r=400;t=200;b=600;"

                        // get the position of the Element
                        EA.DiagramObject diaObj = null;
                        foreach (EA.DiagramObject dObj in dia.DiagramObjects) {
                            if (dObj.ElementID == el.ElementID)
                            {
                                diaObj = dObj;
                                break;
                            }
                        }
                          int left = diaObj.left + 2*(diaObj.right - diaObj.left);
                        int right = diaObj.right + 2 * (diaObj.right - diaObj.left);

                        string position = "l=" + left.ToString() +";r=" + right.ToString() + ";t=" + diaObj.top.ToString() + ";b=" + diaObj.bottom.ToString() + ";";
                        EA.DiagramObject diaObject = dia.DiagramObjects.AddNew(position, "");
                        dia.Update();
                        diaObject.ElementID = elNote.ElementID;
                        diaObject.Update();
                        pkg.Elements.Refresh();

Other ressources are:
- Online Help EA (examples)
- E-Book ScriptingEA from Thomas Kilian

Kind regards,

Helmut



Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Add diagram notes from script
« Reply #2 on: July 04, 2012, 03:28:19 pm »
With "DiagramNotes" do you mean the details of the diagram displayed in the top left corner of the diagram?
In that case I don't thin there's an element you need to add.
You just need to set the EA.Diagram.ShowDetails = 1

Geert

PS. Look at the documentation of EA.Element.Type to find the allowed type strings you can enter in xx.Elements.AddNew()

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +54/-3
    • View Profile
Re: Add diagram notes from script
« Reply #3 on: July 04, 2012, 03:42:09 pm »
Quote
With "DiagramNotes" do you mean the details of the diagram displayed in the top left corner of the diagram?
There is also a Diagram Notes element - the 5th item in the Common toolbox. That has type="Text" and subtype=18.
The Sparx Team
[email protected]

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Add diagram notes from script
« Reply #4 on: July 04, 2012, 04:07:55 pm »
Which is almost, but not quite, the same thing ::)

Geert

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: Add diagram notes from script
« Reply #5 on: July 05, 2012, 03:37:17 am »
Solved!

The suggestions by Geert en KP both work, curiously enough though they result in slightly different diagram notes (most notably the creation and last modified date are absent when using EA.Diagram.ShowDetails = 1)

Thx all for helping,

Paulus