Book a Demo

Author Topic: BPMN2.0 from C# addin  (Read 6548 times)

rmartinezb

  • EA User
  • **
  • Posts: 44
  • Karma: +1/-0
    • View Profile
BPMN2.0 from C# addin
« on: July 15, 2016, 07:23:47 pm »
Hi!
I'm writing an addin in C# that creates a BPMN diagram with data from a mysql DB, but I have no idea how to do for insert lanes into pools or elements into lanes.

This is a part of my code:
Code: [Select]

                for(int i =0; i< poolList.Count; i++)
                {
                    EA.Element poolElement = elements.AddNew(poolList[i][1], "BPMN2.0::" + poolList[i][2]);

                    poolList[i][3] = poolElement.ElementID.ToString();
                    poolElement.Update();

                    EA.DiagramObject dObject = diagram.DiagramObjects.AddNew(poolList[i][1], "BPMN2.0::" + poolList[i][2]);
                    dObject.ElementID = poolElement.ElementID;
                    dObject.Update();
                }

                for (int i = 0; i < laneList.Count; i++)
                {
                    EA.Element laneElement = elements.AddNew(laneList[i][2], "BPMN2.0::Lane" );

                    laneList[i][3] = laneElement.ElementID.ToString();
                    laneElement.Update();

                    EA.DiagramObject dObject = diagram.DiagramObjects.AddNew(laneList[i][2], "BPMN2.0::Lane");
                    dObject.ElementID = laneElement.ElementID;
                    dObject.Update();
                }


                for (int j = 0; j < elementList.Count; j++)
                {
                    EA.Element theElement = elements.AddNew(elementList[j][1], "BPMN2.0::" + elementList[j][2]);
                    theElement.Stereotype = "BPMN2.0::" + elementList[j][2];

                    elementList[j][3] = theElement.ElementID.ToString();
                    theElement.Update();

                    EA.DiagramObject dObject = diagram.DiagramObjects.AddNew(elementList[j][1], "BPMN2.0::" + elementList[j][2]);
                    dObject.ElementID = theElement.ElementID;
                    dObject.Update();
                }

The code works fine, i create the elements (I haven't yet created the connectors) and add them to the diagram. But I do not want to have to drag each lane to their pool and each element to their lane with the mouse, i want do it by coding.
Any tips?

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
Re: BPMN2.0 from C# addin
« Reply #1 on: July 15, 2016, 07:56:42 pm »
Hi,

You are adding all elements to the same collection. You would need to create a collection for the pools first, then for each pool element get a new collection of its elements, to which you add lanes then finally for each lane get a collection and add its elements. So nesting everything in the project browser.

However the real problem would then come as you add elements to the diagram. You are currently just adding with default coordinates. They is a way to place them at specific locations (can't remember the method) ... but this will be very difficult. There is an autolayout method - but this want help with a BPMN diagram :-(....

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: BPMN2.0 from C# addin
« Reply #2 on: July 15, 2016, 08:02:46 pm »
Yes, the auto-layout will not work for good reason. Creating automatically layout for activity diagrams is tricky to impossible since the "flow" is something a machine can only partly recognize. If it's a trivial case, you basically would not use a diagram at all. You could however assist a human by creating a diagram e.g. by offering elements which are connected to an element so you can pick the right one to place it next.

q.

rmartinezb

  • EA User
  • **
  • Posts: 44
  • Karma: +1/-0
    • View Profile
Re: BPMN2.0 from C# addin
« Reply #3 on: July 15, 2016, 08:27:54 pm »
Ok, thanks for the anwers, I'll try that  :)