Part Property Name Issue

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Part Property Name Issue

Postby haitong.zhang@boeing.com » Sun Sep 23, 2018 9:23 pm

screenshot.pptx
I am trying to create the following hierarchical structure:

elem-A
elem-A1
elem-A1.1
elem-A1.2
elem-A2
elem-A2.1
elem-A2.2
elem-B
...

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();
vfb250ad0.setName("3");
vfb250ad0.setOwner(ve3551d6a);
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;
break;
}
}
}

// 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();
vdba254ee.setOwner(ve3551d6a);
vdba254ee.setVisibility(VisibilityKindEnum.getByName('public'));
/* setup end 0 which is occ */
var end0 = vdba254ee.getMemberEnd()[0];
end0.setAggregation(AggregationKindEnum.getByName('composite'));
end0.setName("3");
end0.setVisibility(VisibilityKindEnum.getByName('public'));
end0.setType(vfb250ad0);
end0.setOwner(ve3551d6a);
StereotypesHelper.addStereotype(end0, v43a91e7e);
/* setup end 1 which is used-on */
var end1 = vdba254ee.getMemberEnd()[1];
end1.setName("A1-1");
end1.setVisibility(VisibilityKindEnum.getByName('public'));
end1.setType(ve3551d6a);
end1.setOwner(vfb250ad0);
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.
haitong.zhang@boeing.com
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

Hello,

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()


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

Re: Part Property Name Issue

Postby haitong.zhang@boeing.com » Wed Sep 26, 2018 3:35 pm

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

Re: Part Property Name Issue

Postby noteminnow@gmail.com » Wed Dec 14, 2022 2:09 am

I'm willing to give it a go. We appreciate your help.
noteminnow@gmail.com
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

cron