Hi,
when creating a sysml diagram with the ui.js function dropobjectstodiagram, i get an error. The dropping seems to work anyhow. But I can not have my colleagues have this script with this error message.

my script:
//$DEBUG$ $EXPERIMENTAL$ $ENHANCED_CONTAINMENT_ACCESS$ $ENHANCED_JAVA_ACCESS$
load("~/.lib/factory.js");
load("~/.lib/ui.js");
function findDiagram(scope, name)
{
if (!scope) {
console.error("Scope is undefined in find method!");
return undefined;
}
var found = Global.getFinder(scope).findByType(Metamodel.projectmodel.PJDiagram, true).find("name", name);
if (!found.isEmpty()) {
return found.first();
}
return undefined;
}
function PhysicalDiagrams()
{
if (selection)
{
//create a subdiargram for each Element of a system
for (var nn=0; nn <=selection.length-1;nn++)
{
var thisPhyModel=selection[nn];
var targetModel = finder.findByType(Metamodel.projectmodel.PJPackage, false).and("name", "System Design").asList().get(0);
var theParentDiagram = findDiagram(targetModel, thisPhyModel.name);
dropObjectsToDiagram(thisPhyModel.the_owned_elements, null, theParentDiagram, 500, 150, 2 /* = MOVE */);
console.log ("drawing {0} done", thisPhyModel.name);
}
}
}
PhysicalDiagrams()
the reference model:


to recreate the error:
remove the diagram "New Element" and recreate with the same name (because the finder is looking for the diggram with the same name as the selected element.
The funny thing is, this only happens when more than one port is part of the "New Element". If there is only on port (or none) the dropping works without fault. It makes no difference if there are connections between the port and Elements.