Author Topic: Change the activity parameter direction value  (Read 7151 times)

sandeep bhat

  • EA User
  • **
  • Posts: 36
  • Karma: +0/-0
    • View Profile
Change the activity parameter direction value
« 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

Code: [Select]
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

Code: [Select]
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.


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Change the activity parameter direction value
« Reply #1 on: November 06, 2014, 04:30:54 am »
An activity parameter is not an attribute but an embedded element of type ActivityParameter,

q.

sandeep bhat

  • EA User
  • **
  • Posts: 36
  • Karma: +0/-0
    • View Profile
Re: Change the activity parameter direction value
« Reply #2 on: November 06, 2014, 07:10:22 pm »
So is there any way i can specify the direction?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Change the activity parameter direction value
« Reply #3 on: November 06, 2014, 10:36:57 pm »
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
Code: [Select]
;@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.
« Last Edit: November 06, 2014, 10:38:50 pm by qwerty »

sandeep bhat

  • EA User
  • **
  • Posts: 36
  • Karma: +0/-0
    • View Profile
Re: Change the activity parameter direction value
« Reply #4 on: November 06, 2014, 11:43:35 pm »
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.
Code: [Select]
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)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Change the activity parameter direction value
« Reply #5 on: November 07, 2014, 01:55:25 am »
I got it working:
Code: [Select]
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.
« Last Edit: November 07, 2014, 01:55:55 am by qwerty »

sandeep bhat

  • EA User
  • **
  • Posts: 36
  • Karma: +0/-0
    • View Profile
Re: Change the activity parameter direction value
« Reply #6 on: November 07, 2014, 06:42:03 pm »
Thanks a ton for your help qwerty. I was able to set the direction with the below code
Code: [Select]
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()

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Change the activity parameter direction value
« Reply #7 on: November 07, 2014, 06:44:42 pm »
NP :-) Beware of the snakes.

q.

sandeep bhat

  • EA User
  • **
  • Posts: 36
  • Karma: +0/-0
    • View Profile
Re: Change the activity parameter direction value
« Reply #8 on: November 07, 2014, 09:21:27 pm »
oh yes :)

sandeep bhat

  • EA User
  • **
  • Posts: 36
  • Karma: +0/-0
    • View Profile
Re: Change the activity parameter direction value
« Reply #9 on: November 08, 2014, 12:30:53 am »
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.
Code: [Select]
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()

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Change the activity parameter direction value
« Reply #10 on: November 08, 2014, 02:20:29 am »
Change
Code: [Select]
NewAttr2.TaggedValues.AddNew('min','10')
NewAttr2.Update()
to
Code: [Select]
tv = NewAttr2.TaggedValues.AddNew('min','10')
tv.Update()

q.

sandeep bhat

  • EA User
  • **
  • Posts: 36
  • Karma: +0/-0
    • View Profile
Re: Change the activity parameter direction value
« Reply #11 on: November 08, 2014, 02:22:52 am »
What would i do without you :). Thanks again.

pisokol

  • EA User
  • **
  • Posts: 26
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Change the activity parameter direction value
« Reply #12 on: November 29, 2014, 12:03:24 am »
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...
Code: [Select]
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();

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Change the activity parameter direction value
« Reply #13 on: November 29, 2014, 04:09:42 am »
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.

pisokol

  • EA User
  • **
  • Posts: 26
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Change the activity parameter direction value
« Reply #14 on: December 01, 2014, 08:40:47 pm »
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