Organizing Nodes Inside Group Node Using Python

    header_position = [0.0, 0.0]
    for i in range(0, len(layers)):
        header_position[0] -= layer_stack.node_default_width + node_spacing
        header_position[1] = 0.0

        # Organize all nodes in the layer.
        node_list = get_layer_nodes(self, context, i)
        for node in node_list:
            node.width = layer_stack.node_default_width
            node.location = (header_position[0], header_position[1])
            header_position[1] -= (node.dimensions.y) + node_spacing
            print("Dimension Y: " + str(node.dimensions.y))

When I run this code while selecting the material editor dimension.y is always 0, causing nodes not to be organized properly.

If I toggle into the group node and run this code the dimension.y is correct and nodes are organized properly.

I believe this has something to do with Blender’s context.

Any idea of how to fix this?