Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: sandeep bhat on November 06, 2014, 03:08:42 am
-
Whenever i add an activity parameter to an activity, by default the direction is "in". i want to change this to "out". Would be great if anybody can help me with this. Below is the code i am using in pythoin
NewElem2=SelectedPackage.Elements.AddNew('testActivity','Activity')
NewAttr1=NewElem2.Elements.AddNew('Att1','ActivityParameter')
NewElem2.Update()
NewAttr1.Update()
the above code adds an activity with an activity parameter with all the default values.
I tried to make the same activity parameter(Att1) of a particular type by specifying its ClassifierId
NewElem2=SelectedPackage.Elements.AddNew('testActivity','Activity') NewAttr1=NewElem2.Elements.AddNew('Att1','ActivityParameter')
NewAttr1.ClassifierId=239 (user defined type)
NewElem2.Update()
NewAttr1.Update()
similarly i want to change the direction of the parameter. Basically i am trying to convert a class into an activity.
-
An activity parameter is not an attribute but an embedded element of type ActivityParameter,
q.
-
So is there any way i can specify the direction?
-
Hehe, good question. It turns out that this is stored in the treaded t_xref. You need to edit the according entry and change Description to be
;@PROP=@NAME=direction@ENDNAME;@TYPE=ParameterDirectionKind@ENDTYPE;@VALU=out@ENDVALU;...
where VALU can be in, out, inout or return. Note that the above is just an excerpt. You likely can use a regex to change "VALU=(.*);"
Sick, isn't it?
q.
-
Damn!. so i need to write an sql query to update this entry?
whenever i want to check the direction of an activity this is how i do it.
subElements=Collection.Elements
for index in range(0,len(subElements)):
subElem=subElements.GetAt(index)
props = subElem.CustomProperties;
direction=""
for propsCount in range(0,len(props)):
if(props[propsCount].Name=="direction"):
direction=str(props[propsCount].value)
-
I got it working:
my $ap = $rep->GetTreeSelectedObject();
for my $p (in $ap->CustomProperties) {
print $p->Name . ":" . $p->Value . "\n";
if ($p->Name eq "direction") {
$p->{Value} = "out";
$p->Update();
last;
}
}
$ap->Update();
Note the final update. Without the changes to the properties are not applied. EAUI...
q.
-
Thanks a ton for your help qwerty. I was able to set the direction with the below code
NewElem2=Collection.Elements.AddNew('testActivity','Activity')
NewAttr1=NewElem2.Attributes.AddNew('Att1','u32')
NewAttr2=NewElem2.Elements.AddNew('Att2','ActivityParameter')
NewAttr1.default='1U'
NewAttr2.ClassifierId=239
NewAttr1.Update()
NewAttr2.Update()
for prop in NewAttr2.CustomProperties:
if prop.Name=='direction':
prop.Value='out'
NewAttr2.Update()
NewElem2.Update()
-
NP :-) Beware of the snakes.
q.
-
oh yes :)
-
Well now i am stuck while adding the tagged values for the same activity parameter. I get no exception but it is not shown in the UI. i have Min taggedvalue in the EA. so i want to create a new tagvalue for this activity parameter. Below is the code i am trying , but there is no luck.
NewElem2=Collection.Elements.AddNew('testActivity','Activity')
NewAttr1=NewElem2.Attributes.AddNew('Att1','u32')
NewAttr2=NewElem2.Elements.AddNew('Att2','ActivityParameter')
NewAttr1.default='1U'
NewAttr2.ClassifierId=239
NewAttr1.Update()
NewAttr2.Update()
NewAttr2.TaggedValues.AddNew('min','10')
NewAttr2.Update()
for prop in NewAttr2.CustomProperties:
if prop.Name=='direction':
prop.Value='out'
NewAttr2.Update()
NewElem2.Update()
-
Change
NewAttr2.TaggedValues.AddNew('min','10')
NewAttr2.Update()
to tv = NewAttr2.TaggedValues.AddNew('min','10')
tv.Update()
q.
-
What would i do without you :). Thanks again.
-
I try use this solutions to change CustomProperties sets for element, and I have some questions/problems, could You help me?
1.
I added a new element and checked CustomProperties sets for this element in t_xref -> not found, none rows for this t_object.ea_guid.
2.
I added two elements and set value for direction to "in" for first and "out" for secound.
-> I read (in foreach) all settings CustomProperties sets (?) for this elements, try to change one of them (direction), and update elements. Still I have nothing in t_xref for this t_object.ea_guid.
In GUI it's shown that this CustomProperties are set to these same values for all elements like settings value for the last element in update in foreach ("out").
When I saved (in GUI) showed parameters for this element, rows is added to t_xref.
Do You know, where is mistake in my code? I have no idea...
EA.IDualElement elementActivity = null;
elementActivity = element.Elements.AddNew("Activity1", "Activity");
elementActivity.Update();
EA.IDualElement elementActivityParameter = null;
var position = String.Format("l={0};r={1};t={2};b={3};", 0, 0, 0, 0);
//add 1. element ActivityParameter
elementActivityParameter = elementActivity.Elements.AddNew("ActivityParameter1", "ActivityParameter");
elementActivityParameter.ClassifierID = 123 //ElementID
elementActivityParameter.Update();
elementActivity.Update();
//change CustomProperty
foreach (EA.CustomProperty prop in elementActivityParameter.CustomProperties)
if (prop.Name == "direction") prop.Value = "in";
elementActivityParameter.Update();
elementActivity.Update();
//add to diagram
EA.IDualDiagramObject diagramObject1 = diagram.DiagramObjects.AddNew(position, string.Empty);
diagramObject1.ElementID = elementActivityParameter.ElementID;
diagramObject1.Update();
//add 2. element ActivityParameter
elementActivityParameter = elementActivity.Elements.AddNew("ActivityParameter2", "ActivityParameter");
elementActivityParameter.ClassifierID = 123 //ElementID
elementActivityParameter.Update();
elementActivity.Update();
//change CustomProperty
foreach (EA.CustomProperty prop in elementActivityParameter.CustomProperties)
if (prop.Name == "direction") prop.Value = "out";
elementActivityParameter.Update();
elementActivity.Update();
//add to diagram
EA.IDualDiagramObject diagramObject2 = diagram.DiagramObjects.AddNew(position, string.Empty);
diagramObject2.ElementID = elementActivityParameter.ElementID;
diagramObject2.Update();
-
I got the same results. Two steps: 1) report a bug. The best that can happen is that you need some EA specific coding (who knows). 2) Create an CustomProperties entry in t_xref manually. You could do that in a safe way by first checking if EA has created an entry and if not placing one of your own.
q.
-
Thank you for answer.
I already reported the bug and I look forward to the support.
I changed the code to insert into t_xref and works well