Book a Demo

Author Topic: Creating home-grown diagram types via the API  (Read 4737 times)

Knut Paulsen

  • EA User
  • **
  • Posts: 82
  • Karma: +1/-0
    • View Profile
Creating home-grown diagram types via the API
« on: September 23, 2013, 03:12:18 pm »
Hi guys,

I have a bit of trouble creating custom diagram type from my MDG.

I have created an MDG profile with language elements and diagram profiles. All this works very nice when I use it inside EA, but when I try to create one of my diagrams types via the API, I cannot figure out what to specify for the type parameter to the AddNew call.

I have tried every combination I can think of
  • Stereotype name

Metaclass name
alias
DiagramID
with or without my profile name in front
[/list]

the diagram ends up as a Class or Custom diagram, and consequently, the incorrect toolbox is displayed.

I have read the Scripting EA book, but his example only creates a class diagram, and if I try that it works well. So, only failing for my homegrown diagram types.

any ideas?

br
Knut

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Creating home-grown diagram types via the API
« Reply #1 on: September 23, 2013, 09:35:32 pm »
Try to use the FQN like <YourProfile>::<YourDiagram>

(I'm off site and will have a detailed look later.)

q.
« Last Edit: September 23, 2013, 09:36:22 pm by qwerty »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Creating home-grown diagram types via the API
« Reply #2 on: September 24, 2013, 08:30:01 am »
I made some tests and it's (of course) different. Here's a Perl snippet:
Code: [Select]
my $dia = $pk->Diagrams->AddNew("test", "Analysis");
$dia->Update();
my $id = $dia->DiagramID;
my $sql = "UPDATE t_diagram SET StyleEx='MDGDgm=BPMN2.0::BPEL;' WHERE diagram_id = $id";
$rep->Execute($sql);
This creates a BPEL diagram from the BPMN profile. You need to first supply "Analysis" in order to make the right icon appear in the browser. Then you need to execute the SQL to modify StyleEx where the diagram type is actually stored.

I'll make an amendment in the Scripting book.

q.

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Creating home-grown diagram types via the API
« Reply #3 on: September 24, 2013, 09:37:30 am »
Quote
I made some tests and it's (of course) different. Here's a Perl snippet:
Code: [Select]
my $dia = $pk->Diagrams->AddNew("test", "Analysis");
$dia->Update();
my $id = $dia->DiagramID;
my $sql = "UPDATE t_diagram SET StyleEx='MDGDgm=BPMN2.0::BPEL;' WHERE diagram_id = $id";
$rep->Execute($sql);
This creates a BPEL diagram from the BPMN profile. You need to first supply "Analysis" in order to make the right icon appear in the browser. Then you need to execute the SQL to modify StyleEx where the diagram type is actually stored.

I'll make an amendment in the Scripting book.

q.
Hmmm, I would expect to be able to put "BPMN2.0::BPEL" instead of "Analysis" in the AddNew() command. Doing it as in the snippet, any special default properties of the custom diagram type won't be applied. If you tried with "BPMN2.0::BPEL" in the AddNew() and it didn't work, I think it needs fixing.
« Last Edit: September 24, 2013, 09:39:21 am by KP »
The Sparx Team
[email protected]

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Creating home-grown diagram types via the API
« Reply #4 on: September 24, 2013, 08:20:02 pm »
Ooops. You are absolutely right. Probably I was starting to look in the complicated path as there was no confirmation about my first (correct) assumption.
Code: [Select]
my $dia = $pk->Diagrams->AddNew("test", "BPMN2.0::BPEL");
$dia->Update();
is all you need to do.

Anyway I'll add a note in my Scripting book :)

q.

[edit] As we are in it: how do you create a BPMN2.0::Property? Supplying the 2nd parameter will only populate Type. Assigning it to the stereotype will "somehow" work as it lists the attribute in the correct compartment, but it shows "BPMN2.0::Property" in the stereotype while the manual created only shows "Property" and links it to BPMN2.0 internally. I guess that this is a bug? - Well, I guess so since the manual process creates an entry in t_xref which the automated way does not do. I'll submit a bug report.

[edit2] I got feedback from Sparx. Instead of Stereotype you need to supply StereotypeEx with "BPMN2.0::Property". Further it is necessary to call RefreshModelView in order to make the stereotype appear in the browser. I was also told that the latter will be fixed with V11. I'll add a new MDG Creation chapter to my Scripting book.
« Last Edit: September 27, 2013, 12:06:03 am by qwerty »