Author Topic: Create autom. a Class Diagram after a new Package  (Read 19748 times)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13224
  • Karma: +550/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Create autom. a Class Diagram after a new Pack
« Reply #15 on: October 21, 2010, 07:10:15 pm »
Index is of type "object", so it can be any type, including string or integers.
I think the idea is to allow us to use both the index as the name of the property.
So it seems to be both Get("PackageID") as Get(0) (or Get(1), i don't know if it is zero- or one-based) should work.

Geert

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: Create autom. a Class Diagram after a new Pack
« Reply #16 on: October 25, 2010, 10:15:53 pm »
I'm not really progressing. I've got a problem. With ...
Code: [Select]
diagram1 = package1.Diagrams.AddNew("Logical Diagram", "Logical");
it generates a new diagram. So far so good.
But at first I must set the pointe to the package1 with:
Code: [Select]
package1 = Repository.GetPackageByID(intPackageID)
How I get the intPackgeID?  I have used Info.Get(object index) but without any success. Because I don't find the right parameter for this method. Do you haven any idea?

Thanks


Sven


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13224
  • Karma: +550/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Create autom. a Class Diagram after a new Pack
« Reply #17 on: October 25, 2010, 11:17:41 pm »
Sven,

If I find the time later on I'll try it out, but in the meantime you can try to ask Sparx support using the link on the bottom of the page.
They are usually quite responsive, but keep in mind that they live upside-down, and it's the middle of the night for them at the moment.

Geert

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: Create autom. a Class Diagram after a new Pack
« Reply #18 on: October 26, 2010, 01:11:53 am »
Oh, thanks. That's very nice.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13224
  • Karma: +550/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Create autom. a Class Diagram after a new Pack
« Reply #19 on: October 27, 2010, 05:18:14 pm »
Sven,

I did a little test, and this code works:
Code: [Select]
       public void EA_OnPostNewPackage(EA.Repository Repository, EA.EventProperties Info)
        {
            EA.EventProperty packageID = Info.Get("PackageID");
            EA.Package newPackage = Repository.GetPackageByID(int.Parse((string)packageID.Value));
            string test = newPackage.Name;
        }

Geert

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: Create autom. a Class Diagram after a new Pack
« Reply #20 on: October 29, 2010, 05:12:03 pm »
Your code is very helpful. It generates a new diagram now but in the false level. I need the diagram under the package folder.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13224
  • Karma: +550/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Create autom. a Class Diagram after a new Pack
« Reply #21 on: October 29, 2010, 05:19:04 pm »
Sven,

Where it it creating the diagram then?
Post the code you have now, I'll have a look.

Geert

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: Create autom. a Class Diagram after a new Pack
« Reply #22 on: October 29, 2010, 08:56:38 pm »
Hello Geert,
i think, i have got a update/refresh problem.

Code: [Select]
    public virtual bool EA_OnPostNewPackage(EA.Repository Repository, EA.EventProperties Info)
        {
            EA.EventProperty PackageID = Info.Get("PackageID");
            EA.Package NewPackage = Repository.GetPackageByID(int.Parse((string)PackageID.Value));
    
...

         //------------------------------------------------------------            
            //Zuweisung des Packagenamens auf den Diagramnamen
            //------------------------------------------------------------            

            //Trim() entfernt überflüssige Leerzeichen am Stringanfang und -ende
            packageName = packageName.Trim();
            EA.Diagram NewDiagram = (EA.Diagram)NewPackage.Diagrams.AddNew(Convert.ToString(packageName), "Logical");
            NewPackage.Update();
            NewDiagram.Update();
        

            //------------------------------------------------------------
            //Zuweisung elementName
            //------------------------------------------------------------

            // Werte für Substring(StartWert, Länge) werden berechnet
            // Berechnung der Startposition am String
            startWertStringPosition = packageName.IndexOf('-') + 1;
            // Berechnung der Stringlänge
            zeichenLaengeString = packageName.IndexOf('(') - startWertStringPosition;

            elementName = packageName.Substring(startWertStringPosition, zeichenLaengeString);
            //Trim() entfernt überflüssige Leerzeichen am Stringanfang und -ende
            elementName = elementName.Trim();
            EA.Element NewElement = (EA.Element)NewPackage.Elements.AddNew(Convert.ToString(elementName), "UseCase");
            
            //------------------------------------------------------------            
            //Zuweisung des elementAlias              
            //------------------------------------------------------------

            // Werte für Substring(StartWert, Länge) werden berechnet
            // Berechnung der Startposition am String
            startWertStringPosition = 0;
            // Berechnung der Stringlänge
            zeichenLaengeString = packageName.IndexOf('-');

            elementAlias = packageName.Substring(startWertStringPosition, zeichenLaengeString);
            //Trim() entfernt überflüssige Leerzeichen am Stringanfang und -ende
            NewElement.Alias = elementAlias.Trim();

            //------------------------------------------------------------
            //Zuweisung elementStereotype
            //------------------------------------------------------------

            // Werte für Substring(StartWert, Länge) werden berechnet
            // Berechnung der Startposition am String
            startWertStringPosition = packageName.IndexOf("(Ebene") + 6;//Startwert
            // Berechnung der Stringlänge
            zeichenLaengeString = packageName.IndexOf(")") - startWertStringPosition;

            elementStereotype = packageName.Substring(startWertStringPosition, zeichenLaengeString);
            //Trim() entfernt überflüssige Leerzeichen am Stringanfang und -ende
            NewElement.Stereotype = elementStereotype.Trim();
            NewElement.Update();
            NewPackage.Update();
            NewDiagram.Update();
            NewPackage.Elements.Refresh();


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13224
  • Karma: +550/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Create autom. a Class Diagram after a new Pack
« Reply #23 on: October 29, 2010, 09:40:51 pm »
Seems OK to me, where is it creating the diagram?

Or do you mean that you don't see the diagram and the new element in the project browser immediately?
In that case Repository.AdviseElementChange (NewPackage.Element.ElementID)  should fix that. (although I had some issues with that operation in the past, if it isn't working as expected try Repository.RefreshModelView (NewPackage.PackageID))

Geert

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: Create autom. a Class Diagram after a new Pack
« Reply #24 on: October 29, 2010, 09:50:58 pm »
Yes, I don't see the diagram and the new element in the project browser immediately.
I think he need a update like "reload project".
After then I have got the right view.
When and Where it needs a update?
« Last Edit: October 29, 2010, 10:00:33 pm by marine1981 »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13224
  • Karma: +550/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Create autom. a Class Diagram after a new Pack
« Reply #25 on: October 29, 2010, 09:52:47 pm »
That is "normal". Apparently the GUI doesn't know about updates performed by the API, so you have to tell the GUI to update itself.

Geert

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: Create autom. a Class Diagram after a new Pack
« Reply #26 on: October 29, 2010, 10:01:20 pm »
I think he need a update like "reload project".
After then I have got the right view.
When and Where it needs a update?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13224
  • Karma: +550/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Create autom. a Class Diagram after a new Pack
« Reply #27 on: October 29, 2010, 10:26:16 pm »
Quote
Or do you mean that you don't see the diagram and the new element in the project browser immediately?
In that case Repository.AdviseElementChange (NewPackage.Element.ElementID)  should fix that. (although I had some issues with that operation in the past, if it isn't working as expected try Repository.RefreshModelView (NewPackage.PackageID))

Geert

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: Create autom. a Class Diagram after a new Pack
« Reply #28 on: November 01, 2010, 04:52:26 pm »
I have fixed that but i does not work with one of the both fixes.

Code: [Select]
Repository.AdviceElementChange(NewPackage.Element.ElementID);or
Code: [Select]
Repository.RefreshModelView(NewPackage.PackageID);

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13224
  • Karma: +550/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Create autom. a Class Diagram after a new Pack
« Reply #29 on: November 03, 2010, 05:38:26 pm »
RefreshModelView(0) should reload the whole model, so I would try that first.
If all else fails you can still use Repository.OpenFile (string Filename) to completely reload the model.

Geert