Book a Demo

Author Topic: Creating EA digram using API and C#  (Read 5182 times)

hshahid

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Creating EA digram using API and C#
« on: October 07, 2010, 12:42:56 am »
Hi All,

I using the following C# code to create a diagram with a block, similar to the code given in sparx api examples. I can only able to see the diagram id while debuging the code, but when I open my EA project, I am not able to see any diagram or block added there, please advise?

 
StringBuilder xmlStr = new StringBuilder();
        EA.Element element;
        EA.DiagramObject dObj;
        EA.Diagram diagram;
        EA.Package package;
      
        //EA.Package MyModel = (EA.Package)m_Repository.Models.GetAt(0);
        //package = (EA.Package)MyModel.Packages.GetAt(0);
        package = m_Repository.GetPackageByID(1);
        diagram = (EA.Diagram)package.Diagrams.AddNew("test interface diagram", "Logical");
        
        if (!diagram.Update())
        {
            LblException.Text = diagram.GetLastError();
        }
        diagram.Notes = "Hello there this is a test";
        diagram.Update();

        element = (EA.Element)package.Elements.AddNew("TestBlock", "Class");
        element.MetaType = "Block";
        element.Update();

        dObj = (EA.DiagramObject)diagram.DiagramObjects.AddNew("l=200;r=400;t=200;b=600;", "");
        dObj.ElementID = element.ElementID;
        dObj.Update();

        int testId =  diagram.DiagramID;

alesliehughes

  • EA Administrator
  • EA User
  • *****
  • Posts: 104
  • Karma: +0/-0
    • View Profile
Re: Creating EA digram using API and C#
« Reply #1 on: October 07, 2010, 09:47:02 am »
You need to update the diagram after adding the diagram objects to it.

hshahid

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Creating EA digram using API and C#
« Reply #2 on: October 08, 2010, 01:20:34 am »
Thanks, it worked...