getDocumentPoint of ports

Hi,
I need get the positions of the node ports when the user drop a shape from stencil. To do this, i am using the diagram listener ‘ExternalObjectsDropped’. The problem is the position of the ports always is invalid.

Listener

// Shape drop
 this.diagram.addDiagramListener('ExternalObjectsDropped', e => {
           this.shapeDropListener(e);
});


private shapeDropListener(e: DiagramEvent): void {
    // Location of the node
    const location = e.diagram.selection.first().data.location;
    const shape: Shape = <Shape>(e.diagram.selection.first().data);
    if (!shape) {
        return;
    }
    // Cancels drop
    e.diagram.commandHandler.deleteSelection();
    e.diagram.currentTool.doCancel();
    // Obtains unique name
    const nodeName: string = this.getUniqueName(shape);
    // Creates new node
    const node: Node = this.configuratorService.getNewNode(this.modelView, shape, nodeName, location);
    e.diagram.model.addNodeData(node);
    // Add links
    var n = e.diagram.findNodeForKey(node[this.configuratorService.getNodeKeyProperty()]);
    const panel = <Panel>n.findObject('NODEPANEL');
    if (!panel) {
        return;
    }
    panel.itemArray.forEach((port: Port) => {
        const portPart = panel.findItemPanelForData(port).findObject('PORT');
        console.log(portPart.getDocumentPoint(go.Spot.Center));
    });
}

I can obtain the parts of each port of the node added, but the position of the part is invalid.

I have added the same code in the mouseEnter property of the node and now the value of the port position is ok. Maybe the problem is related with the transaction.

Thanks, Dario

    if (n === null) return;
    n.ensureBounds();
    . . .

Thanks Walter, this did the work

Regards, Dario

FYI, calling ensureBounds is not normally necessary in event handlers such as “ExternalObjectsDropped”, because we’ve already ensured that everything has been measured and arranged and positioned.

It’s only in this case where you have programmatically created a GraphObject that for performance reasons the system hasn’t had a chance to update everything yet. That happens at the end of a top-level transaction.