Parametric Diagram Methods for SysML

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Parametric Diagram Methods for SysML

Postby marc.arias@lmco.com » Mon May 01, 2023 7:40 pm

Hello, Trying to see if there is a package or method that could be use to create a Parametric Diagram automatically using the NoMagic API

I know there currently exists a bunch of different diagrams in the UML diagrams package as referenced below...

Code: Select all
from com.nomagic.magicdraw.uml import DiagramTypeConstants


Code: Select all
from com.nomagic.magicdraw.uml import DiagramType


What about for SysML ? :roll: I used the DiagramType.getCreatableDiagramTypes() for a list and I know "SysML Parametric Diagram" is in that list.
I tried this method call with no success... DiagramType.createDiagramType("SysML Parametric Diagram")
marc.arias@lmco.com
Forum Newbie
Forum Newbie
 
Posts: 11
Posts Rating:2
Joined: Mon Nov 28, 2022 9:16 am

Re: Parametric Diagram Methods for SysML

Postby donsim@nomagic.com » Fri May 12, 2023 6:27 am

Hello,

In case you are using method
com.nomagic.magicdraw.openapi.uml.ModelElementsManager#createDiagram(java.lang.String, com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Namespace)
You can pass diagram type string directly even it is not defined in constants file.
final Diagram diagram = ModelElementsManager.getInstance().createDiagram("Content Diagram" parentForDiagram);
Types for custom (sysml or other) diagrams you can find in diagram descriptor file. This descriptor file is one of plugin file.

for example:
file:
data/defaults/data/diagrams/SysML Internal Block Diagram/descriptor.xml
line 2:
<diagram version="9" type="SysML Internal Block Diagram" baseType="Composite Structure Diagram" abbreviation="ibd" category="SysML Diagrams">

Best regards
Best regards,
Donatas Simkunas
WWW: https://support.nomagic.com
Email: support@nomagic.com
donsim@nomagic.com
Customer Support
Customer Support
 
Posts: 27
Posts Rating:0
Joined: Mon Jan 04, 2010 2:56 am

Re: Parametric Diagram Methods for SysML

Postby marc.arias@lmco.com » Fri May 12, 2023 8:22 am

Thanks for the reply. I expanded the response a bit and applied it specifically to a parametric diagram.
See solution below in Jython ! :)

Code: Select all
from com.nomagic.magicdraw.core import Application
from com.nomagic.magicdraw.openapi.uml import ModelElementsManager as MEM

def makeDiagram(diagtype):
      project = Application.getInstance().getProject()
      parent = project.getPrimaryModel()
      diagram_model = MEM.getInstance().createDiagram(diagtype, parent)
      diagram = project.getDiagram(diagram_model)
      diagram.open()
      return diagram

Calling the function above we get our diagram created and opened in our Cameo working window:
Code: Select all
makeDiagram("SysML Parametric Diagram")
marc.arias@lmco.com
Forum Newbie
Forum Newbie
 
Posts: 11
Posts Rating:2
Joined: Mon Nov 28, 2022 9:16 am


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests

cron