Book a Demo

Author Topic: Create New Root Node  (Read 9149 times)

alext

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Create New Root Node
« on: March 06, 2009, 01:08:12 am »
Does anyone know if there's  a way for creating a new Root node from C#?

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Create New Root Node
« Reply #1 on: March 06, 2009, 04:05:47 am »
EA.Repository.Models.AddNew()

alext

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Re: Create New Root Node
« Reply #2 on: March 06, 2009, 07:02:22 pm »
Thanks for your quick reply Frank...
I have tried the following :

EA.Package newModel = (EA.Package)repository.Models.AddNew("My Test", "");
repository.GetProjectInterface().ReloadProject();
repository.RefreshModelView(newModel.PackageID);


But unfortunatly nothing happens (= MyTest does not appear as a new Model)

What am I doing wrong?

Thanks for your help!

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Create New Root Node
« Reply #3 on: March 06, 2009, 07:15:10 pm »
After

Code: [Select]
EA.Package newModel = (EA.Package)repository.Models.AddNew("My Test", "");
call

Code: [Select]
repository.Models.Refresh()

alext

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Re: Create New Root Node
« Reply #4 on: March 07, 2009, 12:01:17 am »
hmmmm.... that doesn't seem to do the job.
I still don't see the new Module :(

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Create New Root Node
« Reply #5 on: March 07, 2009, 12:46:09 am »
Reload the project, if you had it open at the time.
No, you can't have it!

alext

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Re: Create New Root Node
« Reply #6 on: March 07, 2009, 02:11:07 am »
Allright...the following code still doesn't do anythin :

           EA.Package newModel = (EA.Package)repository.Models.AddNew("My Test", "");
            repository.Models.Refresh();
            repository.RefreshModelView(newModel.PackageID);
            repository.GetProjectInterface().ReloadProject();

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Create New Root Node
« Reply #7 on: March 07, 2009, 10:52:51 am »
After the first line add:

newModel.Refresh();

Better now?
No, you can't have it!

alext

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Re: Create New Root Node
« Reply #8 on: March 09, 2009, 06:25:40 pm »
hmmm... I don't have a Package.Refresh() method.
Do I have an older version of the API? I have EA 7.1.834....

alext

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Re: Create New Root Node
« Reply #9 on: March 09, 2009, 06:40:09 pm »
Okay ... there's a Package.Update() however... and this seems to work!
Thanks for all the help!

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Create New Root Node
« Reply #10 on: March 10, 2009, 12:04:03 am »
You have to call Update whenever you add an item to any collection in EA. This call has to be made before you reference the item in any way. In particular, the Refresh method of the parent collection will not 'see' the item unless you have previously called Update.

For a few items you need to set one or more values before you call Update. An example is a connector, where you add it to one element, but need to set the other end (to the ElementID of whatever is on the other end) before you call Update.

There are also a small number of attributes that it is 'safe' to set before you call Update. An example is the Stereotype attribute.

The general rule of thumb is that you cannot refer to the new item from elsewhere before you call Update. Another rule is that you should not refer to the ID or GUID properties of the new item before calling Update.

One more thing: whenever you change values for an item you also have to call Update. The new values will not be saved until you have done so.

HTH, David

[edit]PS: Once you have Update figured out, Refresh makes sense. The Refresh call affects collections rather than individual elements. It tells EA to reload (i.e. refresh) the collection with current information about each contained element. This will cause the collection to reset its Count attribute if required. It will also ensure that GetByName and GetAt work correctly, and reflect the elements that are currently in the collection.

You don't need to call Refresh unless you have added, or deleted elements, or changed element attributes that might affect retrieval. Note that not all these properties are immediately obvious. The Name of an element is certainly significant, but modifying the Pos attribue (where it exists) or the Position attribute of a Parameter might also affect how the collection behaves.[/edit]
« Last Edit: March 10, 2009, 12:10:37 am by Midnight »
No, you can't have it!

alext

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Re: Create New Root Node
« Reply #11 on: March 10, 2009, 06:36:21 pm »
Thanks for your reply!