Book a Demo

Author Topic: Batch Modification of Model Author  (Read 4057 times)

PSG

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Batch Modification of Model Author
« on: September 11, 2012, 11:26:13 pm »
Is there a way to change the model author of all the elements at the same time?

Luis J. Lobo

  • EA User
  • **
  • Posts: 252
  • Karma: +0/-0
  • IT Consultant
    • View Profile
Re: Batch Modification of Model Author
« Reply #1 on: September 12, 2012, 04:20:51 am »
1. Go to "View | Scripting"

2. Create a new VB Script

3. Paste the following script:



Code: [Select]
option explicit

!INC Local Scripts.EAConstants-VBScript

sub main
      Dim APackage as EA.Package
      
      Set APackage = Repository.GetTreeSelectedPackage
      Call HandlePackage(APackage)
      msgbox "Process finished"
end sub

sub HandlePackage(APackage)
      Dim AnElement as EA.Element
      Dim ASubPackage as EA.Package
      Dim i
      
      'Updates the Package
      if APackage.Element.Author = "old_author" then
            APackage.Element.Author = "new_author"
            APackage.Update()      
      end if
      'Update Elements
      for i = 0 to APackage.Elements.Count - 1
            Set AnElement = APackage.Elements.GetAt(i)
            Call HandleElement(AnElement)
      next
      'Update the SubPackages
      for i = 0 to APackage.Packages.Count - 1
            Set ASubPackage = APackage.Packages.GetAt(i)
            Call HandlePackage(ASubPackage)
      next
end sub

sub HandleElement(AnElement)
      Dim ASubElement as EA.Element
      Dim i
      
      if AnElement.Author = "old_author" then
            AnElement.Author = "new_author"
            AnElement.Update()
      end if
      'Update SubElements
      for i = 0 to AnElement.Elements.Count - 1
            Set ASubElement = AnElement.Elements.GetAt(i)
            Call HandleElement(ASubElement)
      next
end sub

main


4. Replace "old_author" and "new_author" strings in the script with the author to search for and being replaced

5. Save the script

6. Select a Root Node in the Project Browser

7. Run the script

8. Repeat steps 5 and 6 for each Root Node of your repository, or extend the script to handle the all the "Repository.Models" collection

PSG

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Batch Modification of Model Author
« Reply #2 on: September 12, 2012, 08:54:02 am »
Thank you very much!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Batch Modification of Model Author
« Reply #3 on: September 12, 2012, 03:52:32 pm »
The above solution is the best possible solution, but it might take a while to run on large models. (it would probably take a few hours on mine)
In that case you better use a simple update query
For elements and packages
Code: [Select]
update t_object set Author = 'NewAuthor' where Author = 'OldAuthor'And don't forget diagrams (which aren't included in the script from Luis)
Code: [Select]
update t_diagram set Author = 'NewAuthor' where Author = 'OldAuthor'
This will probably execute in less then a second.

Geert