Automating IBD creation

Good evening (or morning for whoever !)

I'm struggling to initialize IBD for a bunch of already defined blocks containing partProperties, proxyPorts and connectors.

I can't find a way to properly create view for connectors, probably because I didn't find a way to create ConnectorEndView objects for related ConnectorEnd objects. Does anybody have an idea ?

Here is an extract of my groovy script: 

SessionManager.getInstance().createSession(project, "Create IBD for " + block.getName());
Diagram diagram = ModelElementsManager.getInstance().createDiagram("SysML Internal Block Diagram", block);
diagram.setOwner(block);
DiagramPresentationElement d = project.getDiagram(diagram);
d.open();

HashMap elementMap = new HashMap ();
for (PresentationElement pe: d.collectPresentationElementsRecursively()) {
    Element element = pe.getElement();
    if (pe instanceof PortView) elementMap.put(element, pe);
    else if (pe instanceof PartView) elementMap.put(element, pe);
    else if (pe instanceof ConnectorView) elementMap.put(element, pe);
}

for (Property partProperty : block.getOwnedAttribute()) {
    if (elementMap.get(partProperty) == null) {
        ShapeElement partElement = PresentationElementsManager.getInstance().createShapeElement(partProperty, d);
        elementMap.put(partProperty, partElement);
        Class childBlock = (Class) partProperty.getType();
        for (Port port : childBlock.getOwnedPort()) {
            if (elementMap.get(port) == null) {
                ShapeElement portElement = PresentationElementsManager.getInstance().createShapeElement(port, partElement);
                elementMap.put(port, portElement);
            }
        }
    }
}

DiagramFrameView frameView = d.getDiagramFrame();
for (Port port: block.getOwnedPort()) {
    if (elementMap.get(port) == null) {
        ShapeElement portElement = PresentationElementsManager.getInstance().createShapeElement(port, frameView);
        elementMap.put(port, portElement);
    }
}

for (Connector connector: block.getOwnedConnector()) {
    if (elementMap.get(connector) == null) {
        ConnectorEnd end1 = connector.getEnd().get(0);
        ConnectorEnd end2 = connector.getEnd().get(1);
        Element role1 = end1.getRole();
        Element role2 = end2.getRole();
        PresentationElement view1 = elementMap.get(role1);
        PresentationElement view2 = elementMap.get(role2);
        ConnectorView view = (ConnectorView) PresentationElementsManager.getInstance().createPathElement(connector, view1, view2);
    }
}
SessionManager.getInstance().closeSession(project);
d.close();