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.