Well, there have been a number of articles in the recent past that brought up the idea/request to "draw" diagrams using a script as for example this one and this one. So far there was no support for that. However, in the attached brand new and well known ui.js library you will find a first solution of such a function named dropObjectsToDiagram.
The name already implies its way of working: it basically replicates what happens if a user drops an element from the model browser to a diagram. The first argument is an array of objects. The second is reserved for future use, than comes the diagram object (PJDIagram!), then x and y position of the drop location and a last optional argument to express the drop behavior.
An example code looks like this:
// we assume factory.js and ui.js loaded and a valid scope for sysml elements
var p1 = Factory.createElement(scope, Metamodel.sysml.SysMLPart);
p1.name = "p1";
var p2 = Factory.createElement(scope, Metamodel.sysml.SysMLPart);
p2.name = "p2";
var c1 = Factory.createRelation(p1, p2, Metamodel.sysml.SysMLConnector);
// create diagram
var dia1 = Factory.createElement(scope, Metamodel.projectmodel.PJDiagram);
dia1.name = "My first system diagram";
// put some elements on that diagram
dropObjectsToDiagram([p1, p2], null, dia1, 500, 150, 2 /* = MOVE */);
You may drop elements from other scopes as well, they will appear similar to the manual process.
I would be cool to get some feedback whether that functions works as expected.
Happy Scripting
Jan