Book a Demo

Author Topic: auto name counter for stereotypes  (Read 5104 times)

B.T.

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
auto name counter for stereotypes
« on: February 12, 2015, 03:13:09 am »
Hallo,
I have the following problem, maybe some one of you had a same problem in the past.

I use EA v11.1

I have created multiple stereotypes from the requirements element.
Code: [Select]
System Requirement(UML::Requirement)
_metatype=System Requirement

Software Requirement(UML::Requirement)
_metatype=Software Requirement

... an so on
until now, all is fine.

but I am not happy with the auto generated name at the creation:

"Software Requrement 1", "Software Requrement 2", ...

This is not so nice i think. I would prefer something like:

"SwR-0001 ", "SwR-0002 ", ...

I know it is possible for the basic EA elements with the auto name counter, where you could define prefix, counter, suffix. I was a little disappointed as is saw this only worked for the basic EA elements and not for stereotypes.

Did some one of you had have the same problem in the past? ... and maybe a solution?

I started working with EA at the end of last year, so I have low experience with it.
I do not know the full spectrum of possibilities and borders of EA.
So let me throw in some simple-headed thoughts of mine.

  • Do EA throw a event where scripts can trigger on element creation?
  • Is multiple inheritance on the stereotype a solution. I just let every ST inherit an additional meta-class witch i do not use any more and use this as trigger for the auto name counter function. But how do i say what meta-class is primary in charge?

Greetings and thanks for your time
--
Michael

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: auto name counter for stereotypes
« Reply #1 on: February 12, 2015, 04:52:39 am »
The easiest (and likely only) was is to write an add-in that subscribes to eaOnPostNewElement and modifies the name based on the stereotype. See Geert's blog on writing and add-in in 10 minutes.

q.
« Last Edit: February 12, 2015, 04:52:56 am by qwerty »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: auto name counter for stereotypes
« Reply #2 on: February 12, 2015, 06:32:25 pm »
Quote
The easiest (and likely only) was is to write an add-in that subscribes to eaOnPostNewElement and modifies the name based on the stereotype. See Geert's blog on writing and add-in in 10 minutes.

q.
Or install EA-Matic and let EA-Matic execute a script you write to change the name.

Geert

Ian Mitchell

  • EA User
  • **
  • Posts: 507
  • Karma: +22/-4
  • The eaDocX and Model Expert guy
    • View Profile
Re: auto name counter for stereotypes
« Reply #3 on: February 17, 2015, 10:42:56 pm »
Worth buying EA-Matic just for this! It's been a missing feature of EA since....forever!
Ian Mitchell, Designer, eaDocX


www.eaDocX.com
www.theartfulmodeller.com

B.T.

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: auto name counter for stereotypes
« Reply #4 on: March 04, 2015, 02:18:14 am »
Thanks for your input.
I solved it by writing a add-in, like qwerty suggested.

I trigger on [edit]http://www.sparxsystems.com/enterprise_architect_user_guide/11/automation_and_scripting/broadcastpostnewelement.html[/edit] and replace on matching one of my stereotypes.

In addition to that, i used the "Auto Names and Counters" feature and set up auto generation  for the Meta Class i used for my stereotypes.

Now every time i create a new element my add-in checks the stereotype of the new element. If it matches to one of my stereotypes i replace the name (not the number part).

Code: [Select]
public bool EA_OnPostNewElement(EA.Repository repository, EA.EventProperties info)
{
    EA.Element element = repository.GetElementByID(info.Get(0).Value);
    bool isStereoType = false;  // flag for matching
    string replacement = "";

    // did the new element match to one of my new stereotypes?
    switch(element.Stereotype)
    {
         case "MyNewStereoType1":
             // load stereotype specific replacement
             replacement = "Type1";
            isStereoType = true;    // notice stereotype match
            break;

         case "MyNewStereoType2":
             // load stereotype specific replacement
             replacement = "Type2";
             isStereoType = true;    // notice stereotype match
             break;

         // and so on ...
    }

    // did the new element matching a centogene stereotype?
    if(isStereoType)
    {
        // yes, replace the default element name for "REQ-..."
        element.Name = element.Name.Replace("REQ", replacement);
        // update the element at EA
        element.Update();
    }

    // true - you did changes, false - you did NO changes
    return isStereoType;
}
« Last Edit: March 04, 2015, 02:19:23 am by B.T. »