Extract Message Number from Sequence Diagram/Interaction

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Extract Message Number from Sequence Diagram/Interaction

Postby kelly.grogan@gd-ms.com » Wed Jan 09, 2019 1:31 pm

Hello,

I am looking to parse either an Interaction or a Sequence Diagram and extract the messages in order as they appear on the diagram. Specifically looking to extract the numbers that are associated to each message and displayed when you enable the Show Message Numbers option. I do not see a method to call in the Message API javadoc. I am able to get the messages from an interaction via the getMessage() method and want to be able to get the number as I loop through the Collection of Messages. Thanks!

Respectfully,

Kelly
kelly.grogan@gd-ms.com
Forum Newbie
Forum Newbie
 
Posts: 2
Posts Rating:0
Joined: Thu Oct 11, 2018 9:15 am

Re: Extract Message Number from Sequence Diagram/Interaction

Postby sean.conway.mbse@gmail.com » Mon Jan 21, 2019 2:55 pm

I am having this exact same problem.

Why hasn't no magic answered this questions?
sean.conway.mbse@gmail.com
Forum Newbie
Forum Newbie
 
Posts: 3
Posts Rating:0
Joined: Mon Nov 26, 2018 1:18 pm

Re: Extract Message Number from Sequence Diagram/Interaction

Postby gdhardy1 » Tue Jan 22, 2019 12:56 pm

You need to access the presentation elements for the messages in the sequence diagram. See the com.nomagic.magicdraw.uml.symbols.paths.SeqMessageView class. This class inherits a getName() and getNumber() method from other classes.

Here's a jython script. Just select the interaction element before you run it.


Code: Select all
import com
from com.nomagic.magicdraw.core import Application
from com.nomagic.magicdraw.uml import Finder

# Method Helpers
App = Application.getInstance()
Log = App.getGUILog()
ActPro = App.getProject()

# SELECT THE INTERACTION IN THE CONTAINMENT TREE
selected = ActPro.getBrowser().getContainmentTree().getSelectedNode().getUserObject()

# Find elements in the scope of the sequence diagram
elements = Finder.byScope().findIncludingPresentationElements(selected, False)

# Empty list to hold message names and numbers
numbers = []
names = []


for el in elements:
    # filter SeqMessageView elements from the collection found by Scope Finder
    if el.class == com.nomagic.magicdraw.uml.symbols.paths.SeqMessageView:
        # get message number as integer
        numbers.append(int(el.getNumber()[0]))
        # get message name
        names.append(str(el.getName()))

# create a dictionary of message numbers (key) and names (value)
messages = dict(zip(numbers, names))

# Log contents of dictionary to notification window
for message in messages.items():
    string = "%s - %s" % (message[0],message[1])
    Log.log(string)
gdhardy1
Forum Newbie
Forum Newbie
 
Posts: 8
Posts Rating:2
Joined: Thu Oct 18, 2018 11:24 am

Re: Extract Message Number from Sequence Diagram/Interaction

Postby kelly.grogan@gd-ms.com » Thu Jan 24, 2019 8:58 am

Perfect! Thank you very much! Works like a charm! :D
kelly.grogan@gd-ms.com
Forum Newbie
Forum Newbie
 
Posts: 2
Posts Rating:0
Joined: Thu Oct 11, 2018 9:15 am


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests