Sparx Systems Forum
Enterprise Architect => General Board => Topic started by: YanDJ on February 12, 2020, 01:45:45 am
-
Hello,
I try to configure the Code Template Editor.
We have define a tag value : "Error_Code" to write all the return code that the functions could return.
But the same tag has been created several times because the size of the value is too big (name + description).
When I generate the code, I use $returnCode += %opTag:"Error_Code"% to retrieve the tag.
But I get only the first tag name "Error_code" the generator find.
I try to find a way to do this in https://www.sparxsystems.com/enterprise_architect_user_guide/15.1/model_domains/taggedvaluemacros.html (https://www.sparxsystems.com/enterprise_architect_user_guide/15.1/model_domains/taggedvaluemacros.html) but I didn't found.
Is it possible to retrieve all the tags "Error_code" at once ?
(Maybe with something like %list="myTag" @separator="\n*"%)
-
Hello,
Pretty sure the answer is No. In the case of multiple same-name tags, EA returns the first one it finds and you can't iterate over tags.
But then it's been a few years since I messed around with code / transform templates. Maybe they've fixed things.
/Uffe
-
To get multiples you'll need to call an add-in.
-
Thank for yours reply, but what is an add-in ?
This is what you are talking about : https://www.sparxsystems.com/resources/developers/autint_vb_calling_from_ea_addin.html
Do you have an example to use it ?
-
I was thinking more along the lines of a Javascript add-in (https://sparxsystems.com/enterprise_architect_user_guide/15.1/automation/modeladdins.html), but same basic idea.
Once you've followed a tutorial to get a basic add-in running, add a signal with the name you want and drop it as a reception onto your add-in.
In the code, the following should do roughly what you want.
if(arguments.length != 4)
return "";
var opGuid = arguments[1];
var tagName = arguments[2];
var separator = arguments[3];
var op = Repository.GetMethodByGuid(opGuid);
if(op == null)
return "";
var ret = "";
for(var i = 0; i < op.TaggedValues.Count; i ++)
{
var tag = op.TaggedValues.GetAt(i);
if(tag.Name == tagName)
{
if(ret != "")
ret += separator;
ret += tag.Value;
}
}
return ret;
In my case the name of my class was CgtAddin and the signal was OperationTags. I called it from an operation template using %EXEC_ADD_IN("CgtAddIn","OperationTags",opGUID, "myTag", "\n")%
-
Hello, so I try to follow your advice.
I wrote a JavaScript (I am not sure it's a add-in) to return all my tag value name "Satisfies" (instead of "Error_Code" in my first post but it should works the same).
I created this script in the Scripting repository cf. image : https://pasteboard.co/IYDqyZ5.png (https://pasteboard.co/IYDqyZ5.png)!INC Local Scripts.EAConstants-JScript
/*
* Script Name:
* Author:
* Purpose:
* Date:
*/
function getSatisfies(args)
{
var tagName = "Satisfies";
var separator = ", ";
var opGuid = arguments[0];
// Select the operation by Guid
var selectedObject as EA.Element;
selectedObject = Repository.GetMethodByGuid(opGuid);
if(selectedObject == null)
{
// Operation not found
Session.Output("Op NotFound");
return "";
}
// Select tags associated to the selected operation
var tags as EA.Collection;
tags = selectedObject.TaggedValues;
if(tags == null)
{
// tag value not found
Session.Output("Tag NotFound");
return "";
}
var ret = "";
for(var i = 0; i < selectedObject.TaggedValues.Count; i ++)
{
var currentTag = selectedObject.TaggedValues.GetAt(i);
// Select only tag value "Satisfies"
if(currentTag.Name == tagName)
{
if(ret != "")
ret += separator;
ret += currentTag.Value;
}
}
Session.Output("Find, List Satisfies: " + ret);
return ret;
}
getSatisfies("{5A1C4F8A-32B5-40a2-B151-391CA4DD8FC2}");This script works well and I got my string with all the value I need. But now I try to call in "Code Template Editor":
$satifies = ""
$satifies = %EXEC_ADD_IN("tagValue","getSatisfies",opGUID)%
But nothing happen when I generate.
What is wrong with my Script? I am pretty sure its not an ADD IN but I can not how to figure this out.
By the way I use a EA Version 13 and on the link you give me it is wrote "This feature is available from Release 15.0", but I saw some topics on this forum talking about EXEC_ADD_IN in 2007 so I imagine I can used it ?
Last question, I have to generate also the design in Word format and I have the same problem with this tagValue.
I had opened an old topic to write my SQL querry to get all my informations : https://www.sparxsystems.com/forums/smf/index.php/topic,43712.msg258942.html#msg258942 (https://www.sparxsystems.com/forums/smf/index.php/topic,43712.msg258942.html#msg258942)
Can I also call the same script in my SQL Fragment ?
Thanks for the help
-
If you're limited to version 13 you'll need to create an add-in in a language like C#. See the help for examples about how to do that.
The javascript add-in described in the help is a way to define your add-in within your model and code it using an external IDE and language. As the help says, that functionality was introduced in version 15.