Author Topic: Change author name for all diagrams and elements  (Read 519 times)

EA_enthusiast

  • EA User
  • **
  • Posts: 169
  • Karma: +0/-0
  • I'm a lifelong learner
    • View Profile
Change author name for all diagrams and elements
« on: November 23, 2023, 01:47:50 pm »
Hello EA experts,

I know this question has been discussed a few times in the past several years. The last time (I came across) was around 2015. Is there a new and easy way to change the author name for all diagrams and elements?

Thank you!
Thank you to all the contributors who spread their knowledge and experience!

vladap

  • EA User
  • **
  • Posts: 74
  • Karma: +0/-0
    • View Profile
Re: Change author name for all diagrams and elements
« Reply #1 on: November 24, 2023, 03:49:09 am »
Hi,

I see three options:

- change in the Database, so that´s easy DB update
- export XML and rewrite it
- you can go to scripting and write JS which goes through all elements and change it

V.

wivel

  • EA User
  • **
  • Posts: 214
  • Karma: +12/-1
  • Driven by Models
    • View Profile
Re: Change author name for all diagrams and elements
« Reply #2 on: November 24, 2023, 04:29:04 am »
Hi

Have changed element author names numerous times using SQL directly on the database. Easy and fast.

Henrik

EA_enthusiast

  • EA User
  • **
  • Posts: 169
  • Karma: +0/-0
  • I'm a lifelong learner
    • View Profile
Re: Change author name for all diagrams and elements
« Reply #3 on: November 24, 2023, 09:19:49 am »
Thank you, vladap and wivel, for your responses.
Is there a step-by-step guide (somewhere) that I can follow for any of these options, as I have not done this before?
Thank you to all the contributors who spread their knowledge and experience!

vladap

  • EA User
  • **
  • Posts: 74
  • Karma: +0/-0
    • View Profile
Re: Change author name for all diagrams and elements
« Reply #4 on: November 24, 2023, 09:35:28 pm »


UPDATE t_diagram
SET Author = 'John'
WHERE Author='Adam';

UPDATE t_object
SET Author = 'John'
WHERE Author='Adam';

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 12783
  • Karma: +532/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Change author name for all diagrams and elements
« Reply #5 on: November 24, 2023, 11:15:07 pm »
To be honest, changing the author directly in the database is somewhat of a nuclear Sledge Hammer option (Trust me, I know what I'm doing)

When not careful this can mess up your model in so many ways.
This circumvents EA completely (and every write protection on the model)

The somewhat more careful option is to use a script

There are a few scripts in the local scripts that traverse a model. You can start with one of those, and update the author in the elements or diagrams you process.

something like

Code: [Select]
dim element as EA.Element
for each element in package.Elements
    if element.Author = "John" then
        element.Author = "Adam"
        element.Update
    end if
next

Geert

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1268
  • Karma: +114/-10
  • Its the results that count
    • View Profile
Re: Change author name for all diagrams and elements
« Reply #6 on: November 26, 2023, 10:53:28 am »
Here is some jscript  I wrote some time ago for changing elements author. It might help you get started.
Code: [Select]

//!INC Local Scripts.EAConstants-JScript
 
// =================================================================================
// Name: Change Author
// Changes the author names to be consistent
// NOTE: Requires a package to be selected in the Project Browser
//
// Related APIs
// =================================================================================
// Element API - http://www.sparxsystems.com/enterprise_architect_user_guide/10/automation_and_scripting/element2.html
// Repository API http://www.sparxsystems.com/enterprise_architect_user_guide/10/automation_and_scripting/repository3.html
// Tagged Value API http://www.sparxsystems.com/enterprise_architect_user_guide/10/automation_and_scripting/taggedvalue.html

function StartWithSelectedPackage()
{
    // Show the script output window
    Repository.EnsureOutputVisible( "Script" );

    Session.Output( "JScript Change Author" );
    Session.Output( "===========================" );

    var thePackage as EA.Package;
    thePackage = Repository.GetTreeSelectedPackage();
   
    if ( thePackage != null && thePackage.ParentID != 0 )
    {
        NavigatePackage( "", thePackage );
    }
    else
    {
        Session.Prompt( "This script requires a package to be selected in the Project Browser.\n" +
            "Please select a package in the Project Browser and try again.", promptOK );
    }
   
    Session.Output( "Done!" );
}

//
// Outputs the packages name and elements, and then recursively processes any child
// packages
//
// Parameters:
// - indent A string representing the current level of indentation
// - thePackage The package object to be processed
//
function NavigatePackage( indent, thePackage )
{
    // Cast thePackage to EA.Package so we get intellisense
    var currentPackage as EA.Package;
    currentPackage = thePackage;
   
    // Add the current package's name to the list
    Session.Output( indent + currentPackage.Name + " (PackageID=" +
        currentPackage.PackageID + ")" );
   
    // Convert the elements this package contains
    ProcessElementsInPackage( indent + "    ", currentPackage );
   
    // Recursively process any child packages
    var childPackageEnumerator = new Enumerator( currentPackage.Packages );
    while ( !childPackageEnumerator.atEnd() )
    {
        var childPackage as EA.Package;
        childPackage = childPackageEnumerator.item();
        NavigatePackage( indent + "    ", childPackage );
       
        childPackageEnumerator.moveNext();
    }
}

//
// Converts the elements of the provided package to the Script output window
//
// Parameters:
// - indent A string representing the current level of indentation
// - thePackage The package object to be processed
//
function ProcessElementsInPackage( indent, thePackage )
{
    // Cast thePackage to EA.Package so we get intellisense
    var currentPackage as EA.Package;
    currentPackage = thePackage;
   
    // Iterate through all elements and add them to the list
    var elementEnumerator = new Enumerator( currentPackage.Elements );
    while ( !elementEnumerator.atEnd() )
    {
        var currentElement as EA.Element;
        currentElement = elementEnumerator.item();
        ProcessElements(indent+"    ",currentElement );
        elementEnumerator.moveNext();
    }
}

function ProcessElements( indent, theElement )
{
    // Cast theElement to EA.Element so we get intellisense
    var currentElement as EA.Element;
 // Debug Comment out when run for real
    Session.Output( indent + "CALLED: ProcessElements for element " + theElement.Name );
    currentElement = theElement;
    currentElement.ObjectType
    ChangeAuthor(indent+"    ",currentElement );
    // Iterate through all embedded elements and add them to the list
    var elementEnumerator = new Enumerator( currentElement.Elements );
    while ( !elementEnumerator.atEnd() )
    {
        var currentElement as EA.Element;
        currentElement = elementEnumerator.item();
        ProcessElements(indent+"    ",currentElement );
        elementEnumerator.moveNext();
    }
}

// Changes name of author
//
// Parameters:
// - indent A string representing the current level of indentation
// - theElement The element object to be processed
function ChangeAuthor( indent, theElement )
{
// Debug Comment out when run for real
    Session.Output( indent + "CALLED: ChangeAuthor(" + theElement.Name + ")" );

    // If stereotype matches source list then convert
    if  (theElement.Author=="Old author name")
    {
        Session.Output( indent + "    Changed Author: " + theElement.Name );
         //uncomment stuff below to actually do conversion.
theElement.Author = "New Author Name";
        //Overright the stereotype list to have only one stereotype
theElement.Update();
    }
}

StartWithSelectedPackage();
Happy to help
:)

EA_enthusiast

  • EA User
  • **
  • Posts: 169
  • Karma: +0/-0
  • I'm a lifelong learner
    • View Profile
Re: Change author name for all diagrams and elements
« Reply #7 on: December 10, 2023, 12:12:15 pm »
Thank you, Geert and Sunshine, for your responses. I appreciate your help.
Thank you to all the contributors who spread their knowledge and experience!