def node_get_connections(node, logical=True):
    """
    From a given node return a set of the connected output ports .

    If logical is set to True only port's nodes contributing to building
    the scene as returned. For example, in the case of a VariableSwitch,
    return only the connected port active.

    Works for any node type even with only one input or no input.

    Args:
        logical(bool): True to return only logical connections.
        node(NodegraphAPI.Node):

    Returns:
        set of NodeGraphAPI.Port: set of ports connected to the passed node
    """

    output = set()
    in_ports = node.getInputPorts()

    for in_port in in_ports:
        # we assume input port can only have one connection
        connected_port = in_port.getConnectedPort(0)
        if not connected_port:
            continue

        if logical:
            # Having a GraphState means the node is evaluated.
            if connected_port.getNode().getGraphState():
                output.add(connected_port)
        else:
            output.add(connected_port)

    return output