Beispiel #1
0
def hotkeys():
    """
    Creates hotkeys that make use of piper scripts.
    """
    # make a custom key set since Maya's default is locked.
    if not pm.hotkeySet(pcfg.hotkey_set_name, exists=True):
        pm.hotkeySet(pcfg.hotkey_set_name, source='Maya_Default')

    # set the current hotkey set to be piper's hotkey set
    pm.hotkeySet(pcfg.hotkey_set_name, current=True, edit=True)

    # CLEAR EXISTING HOTKEY(s)
    # if key is being used, clear it so we can assign a new one.
    if pm.hotkeyCheck(key='c', alt=True):
        pm.hotkey(k='c', alt=True, n='', rn='')

    # ASSIGN NEW HOTKEY(s)
    # create command and assign it to a hotkey
    python_command = 'python("import piper.mayapy.util as myu; myu.cycleManipulatorSpace()")'
    command = pm.nameCommand('cycleManipulator',
                             command=python_command,
                             annotation='Cycles Manipulator Space')
    pm.hotkey(keyShortcut='c', alt=True, name=command)

    pm.displayInfo('Assigned Piper Hotkeys')
Beispiel #2
0
def setHotkeys():
    if pm.hotkeySet('Custom', q=1, exists=1):
        pm.hotkeySet('Custom', edit=1, current=1)
    else:
        pm.hotkeySet('Custom', source="Maya_Default", current=1)
    if pm.windows.runTimeCommand(uca=1, q=1):
        for ca in pm.windows.runTimeCommand(uca=1, q=1):
            if ca.find('Custom') == -1:
                pm.windows.runTimeCommand(ca, edit=1, delete=1, s=1)
    import_command = "import PipelineTools.utilities as ul\nreload(ul)"
    commands_dict = {}
    skin_utilities_dict = {}
    skin_utilities_dict['BindPose'] = (
        "GoToBindPose",  #Command
        "BindPose",  #Command Name
        ['2', True, True, False]  # Key, Ctrl, Alt, Shift
    )
    skin_utilities_dict['PaintWeight'] = (
        "artAttrSkinToolScript 3",  #Command
        "PaintWeight",  #CommandName
        ['1', True, True, False]  # Key, Ctrl, Alt, Shift
    )
    weight_tick = 5
    weight_value = 1.0 / (weight_tick - 1)
    for i in range(weight_tick):
        format_value = '%04.2f' % (weight_value * i)
        format_value = "".join(format_value.split('.'))
        skin_utilities_dict['SetWeight%s' % (format_value)] = ("\n".join([
            import_command,
            "ul.skin_weight_setter(skin_value=%s, normalized=False)" %
            (weight_value * i)
        ]), "SetWeightTo%s" % (format_value), [
            "%d" % (i + 1), False, True, False
        ])
    commands_dict['skin_tool'] = skin_utilities_dict
    nameCommandList = []
    for category in commands_dict:
        for command in commands_dict[category]:
            if pm.runTimeCommand(command, q=1, exists=1):
                pm.runTimeCommand(command, edit=1, delete=1, s=1)
            pm.runTimeCommand(command,
                              category=category,
                              command=commands_dict[category][command][0])
            nameCommand = pm.nameCommand(
                command + "NameCommand",
                ann=commands_dict[category][command][1],
                c=command)
            nameCommandList.append(
                (nameCommand, commands_dict[category][command][2]))
    for nc in nameCommandList:
        print nc
        if nc[1][0]:
            print "hotKey is %s" % nc[1][0]
            pm.hotkey(keyShortcut=nc[1][0],
                      ctl=nc[1][1],
                      alt=nc[1][2],
                      sht=nc[1][3],
                      n=nc[0])
Beispiel #3
0
def create_hotkey(command_hotkey,
                  command=None,
                  name=None,
                  mel=False,
                  maya_default=False):
    # prev_cmd = pm.hotkey(cmdHotkey, query=True, name=True)
    nice_name_hotkey = command_hotkey
    if pm.hotkeySet(q=True, current=True) == "Maya_Default":
        pm.hotkeySet("b_tools", current=True, source='Maya_Default')

    if not name:
        name = command.split(".")[-1]

    if maya_default:
        nc = name
    else:
        rtc = name
        nc = name + "NameCommand"

        if pm.runTimeCommand(rtc, exists=True):
            pm.runTimeCommand(rtc, edit=True, delete=True)

        command_language = "python"
        if mel:
            command_language = "mel"

        rtc = pm.runTimeCommand(rtc,
                                annotation=name + ' Hotkey generated',
                                category=k.Module.name,
                                command=command,
                                commandLanguage=command_language)
        nc = pm.nameCommand(nc,
                            annotation=name + ' nameCommand generated',
                            command=rtc)

    hotkey_params = dict()
    hotkey_params["name"] = nc

    if "alt" in command_hotkey.lower():
        hotkey_params["altModifier"] = True
        command_hotkey = command_hotkey.lower().replace("alt+", "")

    if "ctrl" in command_hotkey.lower():
        hotkey_params["ctrlModifier"] = True
        command_hotkey = command_hotkey.lower().replace("ctrl+", "")

    if "shift" in command_hotkey.lower():
        hotkey_params["shiftModifier"] = True
        command_hotkey = command_hotkey.lower().replace("shift+", "")

    hotkey_params["keyShortcut"] = command_hotkey.lower()
    pm.hotkey(**hotkey_params)
    print "       {}        {}".format(nice_name_hotkey, rtc)
Beispiel #4
0
def startup_deferred():
    logger.info("Backspace Deferred Startup Procedure")
    import pymel.core as pmc

    pipe_path = pmc.Path(__file__).parent.parent
    maya_project_path = "//am-ca-fs02/cg2/04_workflow"
    #maya_project_path = pmc.Path(__file__).splitdrive()[0] / "/04_workflow"

    # DragnDrop Feature
    dragndrop_script_path = pipe_path / "backspace_pipe" / "mel" / "performFileDropAction.mel"
    pmc.mel.evalDeferred('source "{}"'.format(
        dragndrop_script_path.replace("\\", "/")))

    # Set Project
    global project_setup
    if not project_setup:
        try:
            pmc.mel.eval('setProject "{}"'.format(maya_project_path))
        except RuntimeError as e:
            logger.warning(
                "Could not set project at {}".format(maya_project_path))

    # Port Setup
    global port_setup
    if not port_setup:
        try:
            pmc.commandPort(name=":7002", sourceType="python")
        except RuntimeError as e:
            pmc.warning(e)

        port_setup = True

    # Hotkey Setup
    global hotkeys_setup
    if not hotkeys_setup:
        if pmc.hotkeySet("BackspaceHotkeys", query=True, exists=True):
            pmc.hotkeySet("BackspaceHotkeys", edit=True, current=True)
        else:
            pmc.hotkeySet(edit=True, ip=pipe_path + "/BackspaceHotkeys.mhk")

        hotkeys_setup = True
Beispiel #5
0
def _switchToNonDefaultHotkeySet():
    if not hasattr(pm, 'hotkeySet'):
        return
    current = pm.hotkeySet(q=True, cu=True)
    if current == 'Maya_Default':
        existing = pm.hotkeySet(q=True, hotkeySetArray=True)
        if 'Maya_Default_Duplicate' in existing:
            # use the common duplicated set
            pm.hotkeySet('Maya_Default_Duplicate', e=True, cu=True)
            LOG.info("Switched to hotkey set: Maya_Default_Duplicate")
        elif len(existing) > 1:
            # there are other sets, but not with known names
            for e in existing:
                if e != 'Maya_Default':
                    pm.hotkeySet(e, e=True, cu=True)
                    LOG.info("Switched to hotkey set: " + e)
                    break
        else:
            # create a duplicate
            pm.hotkeySet('Maya_Default_Duplicate', src='Maya_Default', cu=True)
            LOG.info("Created duplicate hotkey set: Maya_Default_Duplicate")
Beispiel #6
0
def setHotkeys():
    """Create RuntimeCommand for Hair Ops """
    if pm.hotkeySet('HairOps', q=1, exists=1):
        pm.hotkeySet('HairOps', edit=1, current=1)
    else:
        pm.hotkeySet('HairOps', source="Maya_Default", current=1)
    if pm.windows.runTimeCommand(uca=1, q=1):
        for ca in pm.windows.runTimeCommand(uca=1, q=1):
            if ca.find('HairOps') == -1:
                pm.windows.runTimeCommand(ca, edit=1, delete=1, s=1)
    importCommand = "import MeshHairTool.hairOps as ho\nreload(ho)"
    commandsDict = {}
    hairCommands_dict = {}
    hairCommands_dict["MakeHair"] = ("\n".join(
        [importCommand,
         "ho.makeHairMesh()"]), "Make Hair", ["", False, False, False])
    hairCommands_dict['MakeHairUI'] = ("\n".join(
        [importCommand,
         "ho.makeHairUI()"]), "Make Hair UI", ["", False, False, False])
    hairCommands_dict['DuplicateHair'] = ("\n".join([
        importCommand, "ho.dupHairMesh()"
    ]), "Duplicate Hair along with Controls", ["#", False, False, False])
    hairCommands_dict['MirrorHair'] = ("\n".join([
        importCommand, "ho.dupHairMesh(mirror=True)"
    ]), "Mirror Hair along with Controls", ["%", False, False, False])
    hairCommands_dict['SelectHair'] = ("\n".join([
        importCommand, "ho.pickWalkHairCtrl(d='up')"
    ]), "Select Hair Control Root", ["3", False, True, False])
    hairCommands_dict['SelectAllControls'] = ("\n".join([
        importCommand, "ho.selHair(selectAll=True)"
    ]), "Select All Controls of Hair", ["4", False, True, False])
    hairCommands_dict['SetHairPivotTip'] = ("\n".join([
        importCommand, "ho.selHair(setPivot=True,pivot=-1)"
    ]), "set Hair Control Root Pivot to Root", ["5", False, True, False])
    hairCommands_dict['SplitHairControlUp'] = ("\n".join([
        importCommand, "ho.splitHairCtrl(d='up')"
    ]), "Add a Hair Control Toward Tip", ["2", True, True, False])
    hairCommands_dict['SplitHairControlDown'] = ("\n".join([
        importCommand, "ho.splitHairCtrl(d='down')"
    ]), "Add a Hair Control Toward Root", ["1", True, True, False])
    hairCommands_dict['DeleteHairAll'] = ("\n".join([
        importCommand, "ho.delHair()"
    ]), "Delete Hair with its controls", ["$", False, False, False])
    hairCommands_dict['DeleteHairControl'] = ("\n".join([
        importCommand, "ho.delHair(keepHair=True)"
    ]), "Delete Hair controls but keep Hair Mesh", ["", False, False, False])
    hairCommands_dict['DeleteControlsUp'] = ("\n".join([
        importCommand, "ho.delHair(dType='above', keepHair=True)"
    ]), "Delete All Controls From Select to Tip", ["4", True, True, False])
    hairCommands_dict['DeleteSelectControl'] = ("\n".join([
        importCommand, "ho.delHair(dType='self', keepHair=True)"
    ]), "Delete Select Control", ["3", True, True, False])
    hairCommands_dict['DeleteControlsDown'] = ("\n".join([
        importCommand, "ho.delHair(dType='below', keepHair=True)"
    ]), "Delete All Controls From Select to Root", ["5", True, True, False])
    hairCommands_dict['RebuildControlsUp'] = ("\n".join([
        importCommand, "ho.splitHairCtrl(d='up')"
    ]), "rebuild All Controls From Select to Tip", ["", False, False, False])
    hairCommands_dict['RebuildSelectControl'] = ("\n".join([
        importCommand, "ho.splitHairCtrl(d='self')"
    ]), "rebuild Select Control", ["", False, False, False])
    hairCommands_dict['RebuildControlsDown'] = ("\n".join([
        importCommand, "ho.splitHairCtrl(d='down')"
    ]), "rebuild All Controls From Select to Root", ["", False, False, False])
    hairCommands_dict['PickWalkHideRight'] = ("\n".join([
        importCommand, "ho.pickWalkHairCtrl(d='right')"
    ]), "Pick Walk Right and hide last Select Control",
                                              ["2", False, True, False])
    hairCommands_dict['PickWalkAddRight'] = ("\n".join([
        importCommand, "ho.pickWalkHairCtrl(d='right',add= True)"
    ]), "Pick Walk Right and add to last Select Control",
                                             ["@", False, True, False])
    hairCommands_dict['PickWalkHideLeft'] = ("\n".join([
        importCommand, "ho.pickWalkHairCtrl(d='left')"
    ]), "Pick Walk Left and hide last Select Control",
                                             ["1", False, True, False])
    hairCommands_dict['PickWalkAddLeft'] = ("\n".join([
        importCommand, "ho.pickWalkHairCtrl(d='left',add= True)"
    ]), "Pick Walk Left and add to last Select Control",
                                            ["!", False, True, False])
    hairCommands_dict['HideAllHairCtrls'] = ("\n".join([
        importCommand, "ho.ToggleHairCtrlVis(state='hide')"
    ]), "Hide All Hair Controls", ["t", False, False, True])
    hairCommands_dict['ShowAllHairCtrls'] = ("\n".join([
        importCommand, "ho.ToggleHairCtrlVis(state='show')"
    ]), "Show All Hair Controls", ["t", False, True, True])
    commandsDict['HairOps'] = hairCommands_dict
    nameCommandList = []
    for category in commandsDict:
        for command in commandsDict[category]:
            if pm.runTimeCommand(command, q=1, exists=1):
                pm.runTimeCommand(command, edit=1, delete=1, s=1)
            pm.runTimeCommand(command,
                              category=category,
                              command=commandsDict[category][command][0])
            nameCommand = pm.nameCommand(
                command + "NameCommand",
                ann=commandsDict[category][command][1],
                c=command)
            nameCommandList.append(
                (nameCommand, commandsDict[category][command][2]))
    for nc in nameCommandList:
        print nc
        if nc[1][0]:
            print "hotKey is %s" % nc[1][0]
            pm.hotkey(keyShortcut=nc[1][0],
                      ctl=nc[1][1],
                      alt=nc[1][2],
                      sht=nc[1][3],
                      n=nc[0])