How to get relationship name/string

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

How to get relationship name/string

Postby goodboy16h@yahoo.com » Thu Oct 30, 2014 6:56 am

Hello,

I am trying to parse the UML models using magicdraw API in java. For my case I am using the model attached with the post as my example.

Here is what I am doing, I first get all the elements (into children arraylist) from the top model element (model) as follows:

Code: Select all
         ArrayList children = new ArrayList();
         Element current = model;
         children.add(current);
         // if current element has children, list will be increased.
         for (int i = 0; i < children.size(); i++)
         {
            current = (Element) children.get(i);
            // add all children into end of this list, so it emulates recursion.
            children.addAll(current.getOwnedElement());
         }


Then I iterate through all the elements of children arraylist and record getHumanName() and getHumanType(). I check if the current element is a relationship using

Code: Select all
boolean isRelationship = ModelHelper.isRelationship(current);


Finally I am able to get the supplier and client elements BUT the problem is I am unable to get the name/string of the relationship itself. For example

I do get a relationship as follows:
getHumanName(): Association
getHumanType(): Association
Supplier: Spigot
Client: Faucet\nInlet
But I also want to know that this relationship name is "from"/"to" (or any one might also work) which I tried a lot but could not get.

Please help me, I almost have spent a week on this and am now out of ideas. I thanks a lot in anticipation :)
You do not have the required permissions to view the files attached to this post.
goodboy16h@yahoo.com
Forum Newbie
Forum Newbie
 
Posts: 2
Posts Rating:0
Joined: Thu Oct 30, 2014 6:40 am

Re: How to get relationship name/string

Postby mindaugas.genutis » Thu Oct 30, 2014 9:06 am

Hello,

You may concat association client/supplier names to represent as "From Client to Supplier". To get the association ends use ModelHelper.getFirstMemberEnd() and ModelHelper.getSecondMemberEnd().

Or you may use RepresentationTextCreator.createDefaultRepresentationText(element, false, true) to create a standard format used in containment tree.

Yours Sincerely,

-- Mindaugas Genutis
User avatar
mindaugas.genutis
Customer Support
Customer Support
 
Posts: 510
Posts Rating:37
Joined: Thu Feb 04, 2010 1:57 am
Location: Kaunas

Re: How to get relationship name/string

Postby goodboy16h@yahoo.com » Thu Oct 30, 2014 10:07 am

Thanks a lot.. It really helped me :)
goodboy16h@yahoo.com
Forum Newbie
Forum Newbie
 
Posts: 2
Posts Rating:0
Joined: Thu Oct 30, 2014 6:40 am

Re: How to get relationship name/string

Postby tammy.bogart@g2-ops.com » Mon Feb 10, 2020 10:57 am

I am trying to do the same thing, I need to find all requirements in my model that have a trace relationship with the Supplier = the activeDiagram
I tried the below with both ways on the next to the last line of the below code but neither worked. I am using MagicDraw v19. and this is a macro in JS. Any help is greatly appreciated!!

var CollectionsAndFiles = new JavaImporter (
com.nomagic.magicdraw.core,
com.nomagic.magicdraw.core.project,
com.nomagic.magicdraw.core.Application,
com.nomagic.uml2.ext.jmi.helpers.CoreHelper,
com.nomagic.uml2.ext.jmi.helpers.ModelHelper,
com.nomagic.uml2.ext.jmi.helpers.StereotypesHelper,
java.lang
);

with (CollectionsAndFiles){
var project = Application.getInstance().getProjectsManager().getActiveProject();
var ele = project.getElementByID("_19_0_2_19cb0468_1581105865349_417232_2526");
//get Relationship first
var elementsFactory = Application.getInstance().getProject().getElementsFactory();
var rel = elementsFactory.getAbstractionClass();
var eleSup = CoreHeper.getSecondMemberEnd(); //CoreHelper.getSupplierElement(rel);
Application.getInstance().getGUILog().log(eleSup);
}
tammy.bogart@g2-ops.com
Forum Newbie
Forum Newbie
 
Posts: 16
Posts Rating:0
Joined: Wed Oct 09, 2019 9:11 am


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 6 guests

cron