Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Damir on June 10, 2010, 11:59:44 pm
-
I'm trying to set in an project browser java script a tag's notes field to a value like this:
aTag = theElement.TaggedValues.AddNew("LAUS_CC:Opis:ZaSve","<memo>");
aTag.Notes = "kaj ima lima";
aTag.Update();
theElement.TaggedValues.Refresh();it creates some error. I can't figure out what error (I'm not at home with scripting in EA). If I remove the line aTag.Notes = "kaj ima lima"; then a tag is added to the element. If this line of code is present, the tag is not added to the element. I need to set value of the tag of type <memo> to a certain value.
What is the right way to do this?
Thanks.
-
Read the doc on the addNew(name,type) operation.
So I would expect something like
addNew("myTaggedValueName","TaggedValue");
then you need to set the value to "<memo>", and then you should be fine.
Geert
-
Hi Geert,
thank you for answering. Unfortunatelly that's not working. The documentation is extremely slim here. I'll go into more details what I have already tried out:
Here is the complete code of the script (don't mind the code comments):
function OnProjectBrowserScript()
{
// Get the type of element selected in the Project Browser
var treeSelectedType = Repository.GetTreeSelectedItemType();
switch ( treeSelectedType )
{
case ELEMENT_OT:
{
// Code for when an element is selected
var theElement as EA.Element;
var aTag as EA.TaggedValue;
theElement = Repository.GetTreeSelectedObject();
// dodavanje tagova na razini elementa, nije izdvojeno u zasebnu funkciju, moglo bi se jer je isti dio koda kao za paket.
aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:Neprora[ch269]unskiKorisnici","True");
aTag.Update();
theElement.TaggedValues.Refresh();
aTag = null;
aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:DuNeZupanija","True");
aTag.Update();
theElement.TaggedValues.Refresh();
aTag = null;
aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:HZZO","True");
aTag.Update();
theElement.TaggedValues.Refresh();
aTag = null;
aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:HZZOZZR","True");
aTag.Update();
theElement.TaggedValues.Refresh();
aTag = null;
aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:ZZJZ","True");
aTag.Update();
theElement.TaggedValues.Refresh();
aTag = null;
aTag = theElement.TaggedValues.AddNew("LAUS_CC:Opis:ZaSve","<memo>");
//aTag.Notes = "kaj ima lima";
aTag.Update();
theElement.TaggedValues.Refresh();
aTag = null;
//dodavanje taga za opis za sve na razini atributa elementa
var attributes as EA.Collection;
attributes = theElement.Attributes;
var anAttributeTag as EA.AttributeTag;
anAttributeTag = null;
for ( var i = 0 ; i < attributes.Count ; i++ )
{
var currentAttribute as EA.Attribute;
currentAttribute = attributes.GetAt( i );
anAttributeTag = currentAttribute.TaggedValues.AddNew("LAUS_CC:Opis:ZaSve","<memo>");
anAttributeTag.Update();
currentAttribute.TaggedValues.Refresh();
anAttributeTag = null;
}
break;
}
case PACKAGE_OT:
{
// Code for when a package is selected
var thePackage as EA.Package;
var theElement as EA.Element;
var aTag as EA.TaggedValue;
thePackage = Repository.GetTreeSelectedObject();
theElement = thePackage.Element;
// dodavanje tagova na razini paketa, nije izdvojeno u zasebnu funkciju, moglo bi se jer je isti dio koda kao za element.
aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:Neprora[ch269]unskiKorisnici","True");
aTag.Update();
theElement.TaggedValues.Refresh();
aTag = null;
aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:DuNeZupanija","True");
aTag.Update();
theElement.TaggedValues.Refresh();
aTag = null;
aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:HZZO","True");
aTag.Update();
theElement.TaggedValues.Refresh();
aTag = null;
aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:HZZOZZR","True");
aTag.Update();
theElement.TaggedValues.Refresh();
aTag = null;
aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:ZZJZ","True");
aTag.Update();
theElement.TaggedValues.Refresh();
aTag = null;
aTag = theElement.TaggedValues.AddNew("LAUS_CC:Opis:ZaSve","<memo>");
aTag.Update();
theElement.TaggedValues.Refresh();
aTag = null;
break;
}
default:
{
// Error message
Session.Prompt( "greška, to se ne može napraviti na ovom tipu UML elementa.", 0 );
}
}
}This code WORKS:
- the tags that are being added are defined on the Tagged Value Types tab of the UML Types dialog box.
- All tags that have "Instalacija" string in them are of type "Boolean"
- All tags that have "Opis" string in them are of type "Memo"
- when the script adds a tag like this: aTag = theElement.TaggedValues.AddNew("LAUS_CC:Instalacija:ZZJZ","True"); the first argument is used as the tag name, and the second argument is used as the TAG VALUE not as the tag type.
- in the previous example, if I put for the second argument value "Boolean" instead of "True", the value of the tag is "Boolean" instead of default value for that tag; and on the drop-down list for values for that tag in the Tagged Values window you can (and should) only select values True and False.
- on the other hand, if I change aTag = theElement.TaggedValues.AddNew("LAUS_CC:Opis:ZaSve","<memo>"); to aTag = theElement.TaggedValues.AddNew("LAUS_CC:Opis:ZaSve","WHATEVER I PUT HERE DOESN'T MATTER"); - it nevertheless creates tagged value of type Memo (as it should)...
-
...continued from the previous post
but the value of the tag of type memo is empty. Value for memo tag should be placed in Notes attribute of the tagged value. So I tried
aTag = theElement.TaggedValues.AddNew("LAUS_CC:Opis:ZaSve","<memo>");
aTag.Notes = theElement.Notes;
aTag.Update();
theElement.TaggedValues.Refresh();
But, whenever I try to add any constant or other value to aTag.Notes, something breakes without prompting and the tag is not being created.
Please help
thanks
-
Damir,
Seems like you are using undocumented side effects of the AddNew() operation.
In my code I always do:
wrappedElement.TaggedValues.AddNew(name, "TaggedValue")If needed I then set the value and notes of the tagged value.
In your case that would need to be
aTag.Value = "<memo>";
aTag.Notes = "whatever long explanation you want to write here";
aTag.Update();
Geert
-
hm, nope, it still doesn't work.
I tried following based on your example:
aTag = null;
aTag = theElement.TaggedValues.AddNew("LAUS_CC:Opis:ZaSve","<memo>");
aTag.Value = "<memo>";
aTag.Notes = "kaj ima lima";
aTag.Update();
theElement.TaggedValues.Refresh();
aTag = null;the tag was not created. I found out following:
- if I remove line aTag.Notes = "kaj ima lima"; - the tag is still not being created. - which means that even if I try to do aTag.Value = "<memo>"; - it generates some kind of error.
- if i remove both of those lines - the tag is created.
I'm using EA build 855.
any ideas?
-
Immediately download 857 and see if the problem is still there...
If so, then change the first "<memo>" to not "<memo>" (as Geert has suggested) and see if that changes anything...
I, too, have previously used the same code as you initially disclosed and it used to work...
Paolo
-
Thanks Paolo
that didn't solve the problem. I've isolated the problem - this is a wierd one:
I've created JavaScript initialy (EA generates the skeleton of the code) and that code was presented in these posts - and it worked for everything except assigning values to Notes fields or Value fields.
Then I've created JScript script and copy-pasted everything from JavaScript script to this one - and it all works!
I don't know these languages that much so I can't say should this be normal - in case it isn't - than EA has a bug here...
Regards
Damir
-
Ah... Yes - I was talking about C# in my Add-In.
Please report a bug to Sparx...
Paolo