The following is a script (JScript) for Sparx Systems’ Enterprise Architect that will delete a specified tagged value across a repository (project). As usual no guarantees are offered and you should backup your project before running it.
This is a by product of the development of the forthcoming MDG Technology for TRAK version 0.124 which implements the change (#3418285) to the TRAK metamodel where normal english is used rather than ‘softese’ i.e. ‘Concept Activity’ instead of ‘Concept Activity’ and ‘tools used’ for ‘toolsUsed’. The idea is to make it easier for anyone to read any view since it’s all about communication of ideas.
Most of the development activity at the moment is to provide supporting scripts to change the names of the tagged values and stereotypes affected and to preserve values.
The script to delete a tagged value is
!INC Local Scripts.EAConstants-JScript
/*
* Deletes object attribute (not connector attribute) name across entire repository.
*
* NOTE: Backup uo before running
*
* Nic Plum Eclectica Systems Ltd
*/
function deleteAttribute(oldAttName)
{
// Show the script output window
Repository.EnsureOutputVisible( "Script" );
var allExistingElements as EA.Collection;
var currentAttribute as EA.Attribute;
var theElement as EA.Element;
var taggedValue as EA.TaggedValue;
//limit operation to those elements having a tagged value with the correct name
var SQLstatement="SELECT t_object.Object_ID FROM t_objectproperties INNER JOIN t_object ON t_objectproperties.Object_ID = t_object.Object_ID WHERE t_objectproperties.Property='"+oldAttName+"'";
//select those elements using the query
allExistingElements=Repository.GetElementSet(SQLstatement,2);
Session.Output( "Delete Tagged Value Name: '"+oldAttName+"'" );
Session.Output( "=======================================" );
Session.Output( "Number of repository elements having tagged value '"+ oldAttName+ "' = "+ allExistingElements.Count );
// operate on an element within the returned collection
for ( var i = 0 ; i < allExistingElements.Count ; i++ )
{
theElement = allExistingElements.GetAt(i);
taggedValue = theElement.TaggedValues.GetByName( oldAttName );
if ( taggedValue != null )
{
//have to iterate through collection of tagged values because there is only a means to delete using the index value within the collection
//not a DeleteByName
for (var ttv=0; ttv < theElement.TaggedValues.Count ; ttv++)
{
thisTaggedValue=theElement.TaggedValues.GetAt(ttv);
if ( thisTaggedValue.Name == oldAttName)
theElement.TaggedValues.DeleteAt (ttv,true);
}
taggedValue.Update;
}
}
Session.Output( "Done!" );
Session.Output( "" );
}
deleteAttribute("add tagged value name here");