Author Topic: Script to convert an element type  (Read 6778 times)

phokanson

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Script to convert an element type
« on: December 10, 2014, 12:54:51 am »
Does anyone know of a script to convert all elements of a particular type to another type?

For instance, suppose I have Activity elements through out a project tree and I want to convert those to an element type that I created (derived off of a UML Activity or some other type).  Does something like this exist?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Script to convert an element type
« Reply #1 on: December 10, 2014, 03:17:32 am »
Try the following:
Code: [Select]
Repository.Execute("UPDATE t_object SET Object_Type = 'Action' WHERE Object_Type = 'Activity'")Just place it in a VB script and it will convert all Activities into Actions. [highlight]Beware[/highlight]: This might break your model if handled not wisely. [highlight]Backup before use![/highlight]

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13251
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Script to convert an element type
« Reply #2 on: December 10, 2014, 06:04:20 pm »
If it is something you created yourself in a profile then you'll have to set the stereotype as well.

Geert

phokanson

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Script to convert an element type
« Reply #3 on: December 11, 2014, 01:30:54 am »
When I was looking in the DB yesterday after the 1st response I did notice the stereotype field.  I was planning on changing that as well, but it was nice to see a response specifically calling that out.  Thanks!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13251
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Script to convert an element type
« Reply #4 on: December 11, 2014, 06:11:42 pm »
Attention, don't get fooled by the stereotype field in the database, that is only part of the stereotype story.
The rest is stored in t_xref.
If you use the API (element.StereotypeEx) you should be ok.

Geert

stevesavage

  • EA User
  • **
  • Posts: 119
  • Karma: +4/-0
    • View Profile
Re: Script to convert an element type
« Reply #5 on: December 12, 2014, 02:11:38 am »
Long way of doing this without directly writing to the database.

Use Find in Project to construct your SQL to get the IDs of the elements you want to update.   E.g. SELECT t_object.OBJECT_ID FROM t_object WHERE ....

Once you know you have the right SQL to get the IDs you want.

  • Use Repository.SQLQuery(inSQL) to get an XML recordset containing the matching records.
  • Use one of the XML function libraries in EAScriptLib to parse the XML, and convert the OBJECT_ID nodes in to an array
  • Convert the array in to a list of OBJECT_IDs
  • Use Repository.GetElementSet(inListOfIDs,1)

Loop through the returned collection of EA Element Objects.

selectedElement.Type = newType;
selectedElement.StereoType = newStereoType;
selectedElement.StereoTypeEx = newStereoType;
selectedElement.MetaType = newMetaType;
selectedElement.Update();
selectedElement.SynchTaggedValues(newProfile,newStereoType);
Repository.AdviseElementChange(selectedElement.ElementID);

Example:
selectedElement.Type = "Actor";
selectedElement.StereoType = "OrganizationUnit";
selectedElement.StereoTypeEx = "OrganizationUnit";
selectedElement.MetaType = "OrganizationUnit";
selectedElement.Update();
selectedElement.SynchTaggedValues("TOGAF","OrganizationUnit");
Repository.AdviseElementChange(selectedElement.ElementID);

« Last Edit: December 12, 2014, 02:12:09 am by realitystorm »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8061
  • Karma: +118/-20
    • View Profile
Re: Script to convert an element type
« Reply #6 on: December 12, 2014, 08:57:49 am »
Quote
  • Use Repository.SQLQuery(inSQL) to get an XML recordset containing the matching records.
  • Use one of the XML function libraries in EAScriptLib to parse the XML, and convert the OBJECT_ID nodes in to an array
  • Convert the array in to a list of OBJECT_IDs
  • Use Repository.GetElementSet(inListOfIDs,1)
Or, use Repository.GetElementSet(sqlQuery,2)

stevesavage

  • EA User
  • **
  • Posts: 119
  • Karma: +4/-0
    • View Profile
Re: Script to convert an element type
« Reply #7 on: December 18, 2014, 01:06:27 am »
Thanks Simon, I forgot about that option.