Book a Demo

Author Topic: Script: update attributes of all existing elements  (Read 8164 times)

skelesp

  • EA User
  • **
  • Posts: 45
  • Karma: +0/-0
    • View Profile
Script: update attributes of all existing elements
« on: October 23, 2012, 06:00:11 pm »
Hi,

I've added some tagged values to the "BPMN 1.1 technology.xml" and I can see these tagged values in new elements.

Now I'm wondering how I can update all the existing elements? So all the elements have the same tagged values... (I think scripting is the best way, but maybe someone here knows a better solution)

Thanks!

skelesp


Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: Script: update attributes of all existing elem
« Reply #1 on: October 23, 2012, 07:15:37 pm »
Hi skelesp,

I've never used it before but i think the 'Synchronize Stereotype' option available from the BPMN diagram toolboxes does this for you.

grts,

paulus

skelesp

  • EA User
  • **
  • Posts: 45
  • Karma: +0/-0
    • View Profile
Re: Script: update attributes of all existing elem
« Reply #2 on: October 23, 2012, 08:04:40 pm »
This works, thanks!

Extra question: is there an easy way/script to remove tagged values from all existing elements? Because synchronising doesn't delete removed tagged values

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: Script: update attributes of all existing elem
« Reply #3 on: October 23, 2012, 09:18:36 pm »
I would have expected this to be part of the synchronisation: optional removal of additional tags. :(

Again I haven't done this but I would find out how tags are stored in the EA tables (you can use the SQL tab in the model search for this) and write a SQL statement to remove the ones that are not used anymore.

The SQl statement can be executed using repository.Execute(<sql>).
... and make sure you create a backup of your repository first!...

Takes some effort but if you know SQL it's easier (and a lot faster) then writing some script.

best regards,

Paulus
« Last Edit: October 23, 2012, 09:19:58 pm by pmaessen »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Script: update attributes of all existing elem
« Reply #4 on: October 23, 2012, 11:20:17 pm »
Synch never deletes any tagged values. You need to write a script or a SQL to do that.

q-

skelesp

  • EA User
  • **
  • Posts: 45
  • Karma: +0/-0
    • View Profile
Re: Script: update attributes of all existing elem
« Reply #5 on: October 23, 2012, 11:58:46 pm »
Could you get me started to write this sql statement (which tables etc...). I only need this script/sql statement, so I want to avoid having to search for this information by myself just for this one script...

Thanks in advance!

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: Script: update attributes of all existing elem
« Reply #6 on: October 24, 2012, 01:25:52 am »
OK if you have MS access: rename a copy of your .eap file to .accdb and open this with MS access.

Or you can import the datamodel in EA using Code engineering - Import DB schema from ODBC

I think the table you are looking for is t_objectproperties. But i don't know if any other tables need to be updated.

good luck!

Paulus


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Script: update attributes of all existing elem
« Reply #7 on: October 24, 2012, 02:26:01 am »
A DELETE * FROM t_objectproperties WHERE property = 'name_of_property' will zap all tags named name_of_property. There will be left some orphans in t_xref but that should be ok. However, direct manipulation of EA's tables is tricky and can be dangerous (backup!).

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Script: update attributes of all existing elem
« Reply #8 on: October 24, 2012, 06:34:35 pm »
Much safer is it to delete the tagged values using the API.
See EA.Element.TaggedValues.Delete(int index)

Unless you are 100% sure you know what you are doing you should avoid any and all direct database manipulations.

Geert

skelesp

  • EA User
  • **
  • Posts: 45
  • Karma: +0/-0
    • View Profile
Re: Script: update attributes of all existing elem
« Reply #9 on: October 24, 2012, 07:31:45 pm »
Thanks for all the answsers!

I want to try to make a little script like Geert suggests, but could anyone give me little sample code on how to do it. I haven't got the time to study the object model etc.

I just want to delete all taggedvalues with value 'Test1' or 'Test2' (select * from t_objectproperties where property = 'Test1' OR property = 'Test2') for the elements of type 'activity' (Select * From t_object where Object_Type = 'Activity')

If it isn't allowed to give some code here, I guess it will just take some more time to get the script working :)

Thanks!

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: Script: update attributes of all existing elem
« Reply #10 on: October 26, 2012, 07:33:24 pm »
OK if you are not familiar with scripts and SQL: it's well worth the time to learn this if you are going to use EA extensively.

EA can do a lot but sometimes it's missing some small feature like the one you've run into (just browse the forum...). If you now how to write SQL and scripting then you can sometimes work around that problem and get the job done or spend a lot less time.

That much said, keep in mind Geert's an qwerty's warnings and here's the script that will do what you asked (and since you are new to this i should mention that you need the 'Corporate' edition of EA to actually create and run scripts, look at http://www.sparxsystems.com/products/ea/index.html#editions):

First, create a SQL Select query using the model search window, SQL tab. This is just a sanity thing to make sure that the delete statement we are going to create will indeed select the expected activities:

Code: [Select]
select o.Name, o.CreatedDate,o.ModifiedDate, p.*
from t_objectproperties p
       inner join t_object o on  o.object_id = p.object_id
where p.property in ('Test1','Test2')  
         and o.Object_Type = 'Activity'

Secondly, if you have checked you get the correct activities, all you need to do is change the line select ... into delete p.* (at least, if you are using a plain EAP file for your repository, for other databases consult the internet ('ff googele'  :)) and run this in a script:

Code: [Select]
sub main
      dim SQL :
      SQL = _
      +" delete p.*" _
      +" from t_objectproperties p" _
      +"            inner join t_object o on  o.object_id = p.object_id" _
      +" where p.property in ('Test1','Test2')  " _
      +"            and o.Object_Type = 'Activity'"
      Repository.execute(SQL)
end sub

main

You run the script like this (provided you have EA professional):
  • open the scipt view in EA (view/scripting)
  • creating a script group of type Normal
  • add a new vbscript to this group
  • replace the content of that script with the above
  • BACKUP the repository
  • run it
  • check the result using the SQL select we started with: it should now return no results
  • keep you backup around for some time, just in case

good luck!

Paulus

Oh, and just an afterthought: if you don't have the EA version with scipting enabled you can run the SQL delete directly on the database. if you have an EAP and have MS access: backup the EAP file, rename the extension to .accdb and open it with MS Acces. Run the SQL delete, change the extension back to EAP and check the result in EA.
« Last Edit: October 26, 2012, 07:41:46 pm by pmaessen »

skelesp

  • EA User
  • **
  • Posts: 45
  • Karma: +0/-0
    • View Profile
Re: Script: update attributes of all existing elem
« Reply #11 on: October 26, 2012, 11:05:00 pm »
Thank you very much Paulus! This looks like what I need. I'll test it later today, but it already looks good.