Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Pawel Jasinski on December 16, 2011, 01:02:15 am
-
hi,
I am trying to use latest and greatest SynchTaggedValues at the Element level. When I try from scripting window the following works tip top:
option explicit
!INC Local Scripts.EAConstants-VBScript
sub ApplyStereotypeToElement()
' Show the script output window
Repository.EnsureOutputVisible "Script"
' Get the currently selected package in the tree to work on
dim thePackage as EA.Package
set thePackage = Repository.GetTreeSelectedPackage()
if not thePackage is nothing and thePackage.ParentID <> 0 then
dim i, testElementID
dim elements as EA.Collection
set elements = thePackage.Elements
' Create a new element in the package
dim testElement as EA.Element
set testElement = elements.AddNew( "AddedByScript", "Class" )
testElement.Stereotype = "Principle"
testElement.SynchTaggedValues "CHMM", "Principle"
testElement.Update()
thePackage.Elements.Refresh()
end if
end sub
ApplyStereotypeToElement
when I try vb or c# (code below) the tagged values never show up:
static void Main(string[] args) {
EA.App app = (EA.App)System.Runtime.InteropServices.Marshal.GetActiveObject("EA.App");
String stereo = "Principle";
EA.Repository repo = app.Repository;
EA.Package package = repo.GetTreeSelectedPackage();
EA.Collection elements = package.Elements;
EA.Element newElement = elements.AddNew("added by csharp", "Class");
newElement.Stereotype = stereo;
newElement.SynchTaggedValues("CHMM", stereo);
newElement.Update();
package.Update();
package.Elements.Refresh();
//repo.SynchProfile( "CHMM", stereo);
}
sync at the repo level works as expected (the line is commented out).
Do I have to do anything else when calling it from vb/c#?
Cheers,
Pawel
-
I can not say what it is, but certain stereotypes ("Principle" and "Requirement") are affected here. Some other are not. It can be definition of the stereotype from MDG file or internal magic of EA.
I can understand the conflict, but why it works in script window and doesn't once outside of EA?
Cheers
Pawel