Exemplo n.º 1
0
def disconnected_attributes(settings, members):

    members = cmds.ls(members, long=True)
    original_connections = []
    try:
        for input in settings["inputs"]:

            # Get source shapes
            source_nodes = lib.lsattr("cbId", input["sourceID"])
            sources = [i for i in source_nodes if
                       not cmds.referenceQuery(i, isNodeReferenced=True)
                       and i in members]
            try:
                source = sources[0]
            except IndexError:
                print("source_id:", input["sourceID"])
                continue

            # Get destination shapes (the shapes used as hook up)
            destination_nodes = lib.lsattr("cbId", input["destinationID"])
            destinations = [i for i in destination_nodes if i not in members
                            and i not in sources]
            destination = destinations[0]

            # Break connection
            connections = input["connections"]
            src_attribute = "%s.%s" % (source, connections[0])
            dst_attribute = "%s.%s" % (destination, connections[1])

            # store connection pair
            if not cmds.isConnected(src_attribute, dst_attribute):
                continue

            cmds.disconnectAttr(src_attribute, dst_attribute)
            original_connections.append([src_attribute, dst_attribute])
        yield
    finally:
        # restore connections
        for connection in original_connections:
            try:
                cmds.connectAttr(connection[0], connection[1])
            except Exception as e:
                print(e)
                continue
Exemplo n.º 2
0
def disconnect_plugs(settings, members):
    """Disconnect and store attribute connections."""
    members = cmds.ls(members, long=True)
    original_connections = []
    try:
        for input in settings["inputs"]:

            # Get source shapes
            source_nodes = lib.lsattr("cbId", input["sourceID"])
            if not source_nodes:
                continue

            source = next(s for s in source_nodes if s not in members)

            # Get destination shapes (the shapes used as hook up)
            destination_nodes = lib.lsattr("cbId", input["destinationID"])
            destination = next(i for i in destination_nodes if i in members)

            # Create full connection
            connections = input["connections"]
            src_attribute = "%s.%s" % (source, connections[0])
            dst_attribute = "%s.%s" % (destination, connections[1])

            # Check if there is an actual connection
            if not cmds.isConnected(src_attribute, dst_attribute):
                print("No connection between %s and %s" %
                      (src_attribute, dst_attribute))
                continue

            # Break and store connection
            cmds.disconnectAttr(src_attribute, dst_attribute)
            original_connections.append([src_attribute, dst_attribute])
        yield
    finally:
        # Restore previous connections
        for connection in original_connections:
            try:
                cmds.connectAttr(connection[0], connection[1])
            except Exception as e:
                print(e)
                continue
Exemplo n.º 3
0
def _override():
    import avalon.maya.commands as commands
    import avalon.maya.pipeline as pipeline
    import avalon.maya.lib as lib

    from .pipeline import has_turntable, set_scene_timeline, set_resolution

    # Override avalon.maya container node lister
    log.info("Overriding <avalon.maya.pipeline._ls>")
    pipeline._ls = lambda: lib.lsattr("id", pipeline.AVALON_CONTAINER_ID)

    # Override avalon.maya menu function
    log.info("Overriding <avalon.maya.commands.reset_frame_range>")
    _set_time = (lambda: set_scene_timeline(asset_name=has_turntable()))
    commands.reset_frame_range = _set_time
    log.info("Overriding <avalon.maya.commands.reset_resolution>")
    _set_res = (lambda: set_resolution(asset_name=has_turntable()))
    commands.reset_resolution = _set_res