Book a Demo

Author Topic: Scripting: remove assigned stereotype?  (Read 7562 times)

Hurra

  • EA User
  • **
  • Posts: 184
  • Karma: +0/-0
    • View Profile
    • Find me at LinkedIn!
Scripting: remove assigned stereotype?
« on: April 08, 2017, 12:29:03 am »
Hello!

I have made a simple JScript to add a stereotype to selected elements in the project browser. The problem is that it only adds stereotypes, not remove current stereotype. The applied stereotypes just keeps piling up. How do I remove applied stereotypes?

Thanks!

Robert.

Code: [Select]
!INC Local Scripts.EAConstants-JScript
!INC EAScriptLib.JScript-Dialog


/*
* Project Browser Script main function
*/
function OnProjectBrowserScript()
{
  // Show the script output window
Repository.EnsureOutputVisible( "Script" );

     // Get the type of element selected in the Project Browser
     var selElem as EA.Collection;

     var input=DLGInputBox( 'Enter new stereotype', 'Multi-select element update', '');
     
     selElem = Repository.GetTreeSelectedElements();
     for (i=0; i < selElem.Count; i++) {
var e as EA.Element;
e = selElem.GetAt(i);
e.Stereotype = input;
Session.Output('Element changed: '+e.Name+' changed stereotype to '+e.Stereotype);
e.Update();
e.Refresh();
     }
Session.Output('All selected elements updated.');
}

OnProjectBrowserScript();
always learning!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Scripting: remove assigned stereotype?
« Reply #1 on: April 08, 2017, 06:08:58 am »
Have you tried to just assign it a null-string?

You have to reload the branch with the element's package afterwards.

q.
« Last Edit: April 08, 2017, 06:12:49 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: Scripting: remove assigned stereotype?
« Reply #2 on: April 08, 2017, 04:37:05 pm »
Have you tried to just assign it a null-string?

You have to reload the branch with the element's package afterwards.

q.

Also loose the call to Refresh() and try it with StereotypeEx iso Stereotype. For some reason that seems to work better.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Scripting: remove assigned stereotype?
« Reply #3 on: April 08, 2017, 05:05:17 pm »
It seems like Stereotype only works as long as there is only a single stereotype assigned. As Geert suggested StereotypeEx replaces multiple assignments. It also respects comma inside the passed stereotype and will split it into single tokens (what a crude interface). StereotypeEx had been introduced in a later EA release since older versions allowed only a single stereotype. Now this is completely broken. Well. EAUI.

q.

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Scripting: remove assigned stereotype?
« Reply #4 on: April 10, 2017, 11:33:23 am »
As Geert suggested, assign your value to StereotypeEx, not Stereotype.

Assigning values to Element.Stereotype intentionally does not overwrite existing stereotypes. If there is an existing stereotype on the element, then assigning a value to Stereotype will set that new value as the primary stereotype and the old value becomes a secondary stereotype.

Assigning to Element.StereotypeEx will overwrite any existing stereotypes on the element.

It's been that way for a very long time. (EA 6.5?)

Hurra

  • EA User
  • **
  • Posts: 184
  • Karma: +0/-0
    • View Profile
    • Find me at LinkedIn!
Re: Scripting: remove assigned stereotype?
« Reply #5 on: April 11, 2017, 09:05:05 pm »
Thank you for all your answers!

I changed .stereotype to .stereotypeex which solved the issue!
always learning!