Book a Demo

Author Topic: retrive currentDiagram  (Read 4503 times)

defi

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
retrive currentDiagram
« on: April 29, 2012, 01:42:51 am »
Hi!
I'm tying to do an add-in in C#. To begin with the code i have to retrieve the currentDiagram that i have on Enterprise Architect. I use the following code:

maindiagram = repository.GetCurrentDiagram();
where maindiagram is defined like an EA.Diagram.

When i debug the whole program it gets me the warning that maindiagram  is always = 0, how is that possible?
Can someone please help me?

Thank you.

stao

  • EA User
  • **
  • Posts: 137
  • Karma: +0/-0
    • View Profile
Re: retrive currentDiagram
« Reply #1 on: April 29, 2012, 03:25:14 am »
do you mean == null ?
if thats the case you dont have a diagram opened.
repository.GetCurrentDiagram()
always shows the currently opened and shown diagram

defi

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
Re: retrive currentDiagram
« Reply #2 on: April 29, 2012, 04:16:02 am »
Yes sorry, == null.
But i open the diagram that i made and then start the add-in with the diagram open and nothing, it result ==null.
I don't get it why.

stao

  • EA User
  • **
  • Posts: 137
  • Karma: +0/-0
    • View Profile
Re: retrive currentDiagram
« Reply #3 on: April 29, 2012, 05:12:37 am »
never stepped over this.
for me getCurrentDiagram() works quite well.
Perhaps it could be useful if you provide us some code of yours.

defi

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
Re: retrive currentDiagram
« Reply #4 on: April 29, 2012, 05:15:20 am »
Here is the code where i make the connection with the diagram in enterprise architect.

public MDGBuilder(EA.Repository repository)
        {
            Console.WriteLine("Hello");
            
            MDG graph = new MDG();
            //collegamento con il diagramma in Enterprise Architect
            EA.Diagram maindiagram; //diagramma corrente
            this.modelRepository = repository; //repository del diagramma
            maindiagram = repository.GetCurrentDiagram(); //recupero del diagramma
            if (maindiagram != null)
            {
                this.diagramId = maindiagram.DiagramID; //identificativo del diagramma
            }
            buildMDG(graph);
            calculateCycle();
            
            
        }

i hope it helps you to discover the problem. Thank you.

g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: retrive currentDiagram
« Reply #5 on: April 30, 2012, 12:36:49 am »
Hi,
I guess your code is called as reaction to the EA_Connect() AddIn event, right?
This event occurs on startup of EA, so if you open a diagram this will occur after(!) this event was issued, in this state getCurrentDiagram() will never see a currently opened diagram.
This might also be the reason for the issues you have mentioned in your other thread posted here.
I think you wil be better off to initiate your AddIn specific actions as reaction on either the EA_OnPostOpenDiagram() event or even better to an AddIn specific menu command selection.

BTW, you might find Geert Bellekens AddIn framework helpful to use as base for C# EA AddIn development: https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework
He also posted some useful articles about this in the community site, e.g. http://community.sparxsystems.com/tutorials/tool-integration/create-your-first-c-enterprise-architect-add-10-minutes

Best regards and HTH,
Günther
Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/

defi

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
Re: retrive currentDiagram
« Reply #6 on: April 30, 2012, 04:17:49 am »
My EA_Connect() is the following
Code: [Select]
public string EA_Connect(Repository repository)
        {
            return "";
        }


is better if I remove it and put the other one that you adviced me to?


Thank you a lot for your help, and the links that you send me will be very helpful to me.
Thank you a lot!
« Last Edit: April 30, 2012, 10:15:32 pm by defi »