Book a Demo

Author Topic: Assign Activity to Operations behavior  (Read 9403 times)

dgoetz

  • EA User
  • **
  • Posts: 35
  • Karma: +0/-0
    • View Profile
Assign Activity to Operations behavior
« on: November 26, 2021, 10:13:54 pm »
I try adding an activity for all operations of a class using an Add-In.
It works when the function is exited and returns to EA. The Behavior attribute contains the activity's GUID in EA.

But when I read the Behavior attribute later in the Add-In before it is exited, it is empty.

Is there any Update-Refresh trick? I tried element.Methods.Refresh(); element.Update(); and element.Refresh(); without any effect.

Dieter

Code: [Select]
EA.Package package; EA.Element element; // actually assigned in the Add-In

foreach (EA.Method method in element.Methods)
{
EA.Element activity = package.Elements.AddNew("Name", "Actvity"); // add new activity
method.Behavior = activity.ElementGUID;  // assign activity to methods behavior
method.StyleEx = "ShowBeh=1;";
method.Update();
string behavior = method.Behavior;  // behavior contains GUID of new activity -> OK
}
foreach (EA.Method method in element.Methods)
{
string behavior = method.Behavior;   // -> behavior is empty
}

Sparx EA V15.2.1559

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Assign Activity to Operations behavior
« Reply #1 on: November 26, 2021, 10:42:33 pm »
Hi Dieter,

Try saving the ID of the methods, then once you've done the .Update(), retrieve the method via the ID directly from the Repo.

When I was developing Add-Ins, I found EA would "lose its way when dealing with collection based items.  Getting it back again solved the issue.

HTH,
PAolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Assign Activity to Operations behavior
« Reply #2 on: November 26, 2021, 11:26:27 pm »
A rare case where you need a Refresh() on the collection between the loops.

q-

dgoetz

  • EA User
  • **
  • Posts: 35
  • Karma: +0/-0
    • View Profile
Re: Assign Activity to Operations behavior
« Reply #3 on: November 26, 2021, 11:33:28 pm »
Hi Paolo,

thanks a lot. It works.

Dieter

Code: [Select]
        EA.Package package; EA.Element element; // actually assigned in the Add-In

foreach (EA.Method method in element.Methods) // maybe replace foreach loop by for loop also
{
EA.Element activity = package.Elements.AddNew("Name", "Actvity"); // add new activity
method.Behavior = activity.ElementGUID;  // assign activity to methods behavior
method.StyleEx = "ShowBeh=1;";
method.Update();
string behavior = method.Behavior;  // behavior contains GUID of new activity -> OK
}
        for (short idx = 0; idx < element.Methods.Count; idx++)
{
                EA.Method elementMethod = this.element.Methods.GetAt(idx);
                EA.Method method = EArepo.GetMethodById(elementMethod.MethodID);

string behavior = method.Behavior;   // behavior contains GUID of new activity -> OK
}