Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Paulus 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:
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
-
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
-
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()
-
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.
-
Which is almost, but not quite, the same thing ::)
Geert
-
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