Part Property Name Issue

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Part Property Name Issue

Postby » Sun Sep 23, 2018 9:23 pm

I am trying to create the following hierarchical structure:


besides all those elements, I also create composition associations (part properties) between parent elem to its direct children elems.
the issue I run into is that the name of part property is different from what the code writes (setName("name")). There is no name collision among the siblings.
this causes the confusions and error in my post-processing. The code is written is to name the part property same as child elem.

This issue does not happen in most of the cases, but just sometimes, the code to create the parent, child elements, part properties, and associations are same.

Here is the javascript code:

var ve3551d6a = Finder.byQualifiedName().find(proj, "PrdView::CCS::Occurrences::A1::A1-1");
var vfb250ad0 = Finder.byQualifiedName().find(proj, "PrdView::CCS::Occurrences::A1::A1-1::3");
var v57c785b8 = StereotypesHelper.getStereotype(proj, "Pin", profile);
// create the child element PrdView::CCS::Occurrences::A1::A1-1::3
if (vfb250ad0 === null) {
var ve3551d6a = Finder.byQualifiedName().find(proj, "PrdView::CCS::Occurrences::A1::A1-1");
vfb250ad0 = proj.getElementsFactory().createClassInstance();
StereotypesHelper.addStereotype(vfb250ad0, v57c785b8);
StereotypesHelper.addStereotype(vfb250ad0, block);
StereotypesHelper.addStereotype(vfb250ad0, v1eaf5a4a);
// create the tags, skipped
StereotypesHelper.setStereotypePropertyValue(vfb250ad0, v57c785b8, "guid", "F6037B8D-4A54-4B51-ABC2-F70B419C794D");

// try to check if there is composition assocation existing to avoid recreation
var ve3551d6a = Finder.byQualifiedName().find(proj, "PrdView::CCS::Occurrences::A1::A1-1");
var found = false;
for each (var p in ve3551d6a.getOwnedElement()) {
if (p instanceof Property && p.getName() === vfb250ad0.getName()) {
var assoc = p.getAssociation();
if (assoc !== null && CoreHelper.getSupplierElement(assoc) === vfb250ad0) {
found = true;

// create part property and composition association, the name is set to 3, but magicdraw shows 38.
if (!found) {
/* create directed composition - part (used-on) */
var vdba254ee = proj.getElementsFactory().createAssociationInstance();
/* setup end 0 which is occ */
var end0 = vdba254ee.getMemberEnd()[0];
StereotypesHelper.addStereotype(end0, v43a91e7e);
/* setup end 1 which is used-on */
var end1 = vdba254ee.getMemberEnd()[1];
StereotypesHelper.addStereotype(end1, v7e3b8aae);

I attached the screenshot to show how that part looks like in the containment tree and spec window.

The javascripts import a large amount of data, logic is same and same code is repeated with different elements.

My questions are:
1) Why the property names got changed during the creation?
2) Which APIs I should call to get Type of part property since I can relay on Name to decide if the composition already existing.

Thanks for the help!
You do not have the required permissions to view the files attached to this post.
Forum Newbie
Forum Newbie
Posts: 8
Posts Rating:0
Joined: Tue Jul 10, 2018 4:10 pm

Re: Part Property Name Issue

Postby Rolandas » Wed Sep 26, 2018 12:44 am


1) SysML in MagicDraw has code, to auto rename association ends, depeding on Block it's connected to when it's created or Block name is changed from blank to something.
Please check also "Project Options->General->SysML->Rename Property on Type Change" to be turned off also.
What you will need to do is, when you close session and create the association ends, you will need again to create a new session and rename them again.

2) You can just take part property, and do this ((TypedElement)partProperty).getType()

No Magic Support Team
Customer Support
Customer Support
Posts: 234
Posts Rating:19
Joined: Mon Jul 30, 2012 3:59 am

Re: Part Property Name Issue

Postby » Wed Sep 26, 2018 3:35 pm

I will give a try. Thanks for the support!
Forum Newbie
Forum Newbie
Posts: 8
Posts Rating:0
Joined: Tue Jul 10, 2018 4:10 pm

Re: Part Property Name Issue

Postby » Wed Dec 14, 2022 2:09 am

I'm willing to give it a go. We appreciate your help.
Forum Newbie
Forum Newbie
Posts: 1
Posts Rating:0
Joined: Wed Dec 14, 2022 2:04 am

Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests