Book a Demo

Author Topic: Change the name of the elements by Script  (Read 3841 times)

utilisateurEA

  • EA User
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Change the name of the elements by Script
« on: May 25, 2010, 07:41:53 pm »
Hello,

I’d like to modify by an Addin (a C# script) the name of all my elements. For instance Iwant to try to add ā€œ1ā€ at the end of these elements.

I tried something like this

while (i_nbElem < Coll.Count)
{
obj = Coll.GetAt(i_nbElem);
EA.Element All_Elem = (EA.Element)obj;                            
obj.All_Elem.Name.Insert(All_Elem.Name.Length, 1.Tostring() );
i_nbElem++;
}

But it doesn't change anything.
I think I change the name of something which is not the element of EA. But how can I change the name of the element in the model ?

Thank you

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Change the name of the elements by Script
« Reply #1 on: May 25, 2010, 07:47:01 pm »
you forgot to save the changes using update()

try this:
Code: [Select]
while (i_nbElem < Coll.Count)
{
obj = Coll.GetAt(i_nbElem);
EA.Element All_Elem = (EA.Element)obj;                            
obj.All_Elem.Name.Insert(All_Elem.Name.Length, 1.Tostring() );
ALL_Elem.Update();
i_nbElem++;
}

Geert

utilisateurEA

  • EA User
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: Change the name of the elements by Script
« Reply #2 on: May 25, 2010, 08:17:46 pm »
It does'nt work...

Don't you think the problem is that I make my changes on a cast object whereas directly on my object ?
If I apply my change on my element does it implies automatically that the change will be on the object too ?

Thanks

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Change the name of the elements by Script
« Reply #3 on: May 25, 2010, 08:46:20 pm »
Maybe like this?
Code: [Select]
while (i_nbElem < Coll.Count)
{
obj = Coll.GetAt(i_nbElem);
EA.Element All_Elem = (EA.Element)obj;                    
All_Elem.name =  obj.All_Elem.Name.Insert(All_Elem.Name.Length, 1.Tostring() );
ALL_Elem.Update();
i_nbElem++;
}

Geert

utilisateurEA

  • EA User
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: Change the name of the elements by Script
« Reply #4 on: May 25, 2010, 09:24:01 pm »
Now It works.

Thank you
« Last Edit: May 25, 2010, 09:26:11 pm by utilisateurEA »