Python maya.mel.eval() Examples

The following are 30 code examples of maya.mel.eval(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module maya.mel , or try the search function .
Example #1
Source File: capture.py    From pyblish-bumpybox with GNU Lesser General Public License v3.0 7 votes vote down vote up
def parse_active_scene():
    """Parse active scene for arguments for capture()

    *Resolution taken from render settings.

    """

    time_control = mel.eval("$gPlayBackSlider = $gPlayBackSlider")

    return {
        "start_frame": cmds.playbackOptions(minTime=True, query=True),
        "end_frame": cmds.playbackOptions(maxTime=True, query=True),
        "width": cmds.getAttr("defaultResolution.width"),
        "height": cmds.getAttr("defaultResolution.height"),
        "compression": cmds.optionVar(query="playblastCompression"),
        "filename": (cmds.optionVar(query="playblastFile")
                     if cmds.optionVar(query="playblastSaveToFile") else None),
        "format": cmds.optionVar(query="playblastFormat"),
        "off_screen": (True if cmds.optionVar(query="playblastOffscreen")
                       else False),
        "show_ornaments": (True if cmds.optionVar(query="playblastShowOrnaments")
                       else False),
        "quality": cmds.optionVar(query="playblastQuality"),
        "sound": cmds.timeControl(time_control, q=True, sound=True) or None
    } 
Example #2
Source File: dpFacialControl.py    From dpAutoRigSystem with GNU General Public License v2.0 7 votes vote down vote up
def dpLoadBSNode(self, *args):
        """ Load selected object as blendShapeNode
        """
        selectedList = cmds.ls(selection=True)
        if selectedList:
            if cmds.objectType(selectedList[0]) == "blendShape":
                cmds.textField(self.bsNodeTextField, edit=True, text=selectedList[0])
                self.dpLoadBSTgtList(selectedList[0])
                self.bsNode = selectedList[0]
            elif cmds.objectType(selectedList[0]) == "transform":
                meshList = cmds.listRelatives(selectedList[0], children=True, shapes=True, noIntermediate=True, type="mesh")
                if meshList:
                    bsNodeList = cmds.listConnections(meshList[0], type="blendShape")
                    if bsNodeList:
                        self.dpLoadBSTgtList(bsNodeList[0])
                        self.bsNode = bsNodeList[0]
                    else:
                        mel.eval("warning \""+self.langDic[self.langName]["e018_selectBlendShape"]+"\";")
                else:
                    mel.eval("warning \""+self.langDic[self.langName]["e018_selectBlendShape"]+"\";")
            else:
                mel.eval("warning \""+self.langDic[self.langName]["e018_selectBlendShape"]+"\";")
        else:
            mel.eval("warning \""+self.langDic[self.langName]["e018_selectBlendShape"]+"\";") 
Example #3
Source File: dpRivet.py    From dpAutoRigSystem with GNU General Public License v2.0 6 votes vote down vote up
def dpCheckGeometry(self, item, *args):
        isGeometry = False
        if item:
            if cmds.objExists(item):
                childList = cmds.listRelatives(item, children=True)
                if childList:
                    self.itemType = cmds.objectType(childList[0])
                    if self.itemType == "mesh" or self.itemType == "nurbsSurface":
                        if self.itemType == "mesh":
                            self.meshNode = childList[0]
                        isGeometry = True
                    else:
                        mel.eval("warning \""+item+" is not a geometry.\";")
                else:
                    mel.eval("warning \"Select the transform node instead of "+item+" shape, please.\";")
            else:
                mel.eval("warning \""+item+" does not exists, maybe it was deleted, sorry.\";")
        else:
            mel.eval("warning \"Not found "+item+"\";")
        return isGeometry 
Example #4
Source File: uExport.py    From uExport with zlib License 6 votes vote down vote up
def loadUiType(uiFile):
    """
    Pyside lacks the "loadUiType" command, so we have to convert the ui file to py code in-memory first
    and then execute it in a special frame to retrieve the form_class.
    http://tech-artists.org/forum/showthread.php?3035-PySide-in-Maya-2013 (ChrisE)
    """
    parsed = xml.parse(uiFile)
    widget_class = parsed.find('widget').get('class')
    form_class = parsed.find('class').text

    with open(uiFile, 'r') as f:
        o = StringIO()
        frame = {}

        pysideuic.compileUi(f, o, indent=0)
        pyc = compile(o.getvalue(), '<string>', 'exec')
        exec pyc in frame

        #Fetch the base_class and form class based on their type in the xml from designer
        form_class = frame['Ui_%s'%form_class]
        base_class = eval('QtWidgets.%s'%widget_class)
    return form_class, base_class 
Example #5
Source File: dpSelectAllControls.py    From dpAutoRigSystem with GNU General Public License v2.0 6 votes vote down vote up
def dpMain(self, *args):
        """ Main function.
            Check existen nodes and call the scripted function.
        """
        callAction = False
        self.allGrp = self.dpFindAllGrpBySelection()
        if self.allGrp:
            callAction = True
        else:
            allGrpList = self.dpCountAllGrp()
            if allGrpList:
                if len(allGrpList) > 1:
                    self.allGrp = cmds.confirmDialog(title=self.langDic[self.langName]["m166_selAllControls"], message=self.langDic[self.langName]["m168_wichAllGrp"], button=allGrpList)
                else:
                    self.allGrp = self.dpCheckAllGrp(self.allGrp)
                if self.allGrp:
                    callAction = True
                else:
                    self.allGrp = self.dpFindAllGrp()
                    if self.allGrp:
                        callAction = True
        if callAction:
            self.dpSelectAllCtrls(self.allGrp)
        else:
            mel.eval("warning \""+self.langDic[self.langName]["e019_notFoundAllGrp"]+"\";") 
Example #6
Source File: dpRivet.py    From dpAutoRigSystem with GNU General Public License v2.0 6 votes vote down vote up
def dpLoadGeoToAttach(self, geoName=None, geoFromUI=None, *args):
        """ Load selected object a geometry to attach rivet.
        """
        if geoName:
            selectedList = [geoName]
        elif geoFromUI:
            selectedList = [cmds.textField(self.geoToAttachTF, query=True, text=True)]
        else:
            selectedList = cmds.ls(selection=True)
        if selectedList:
            if self.dpCheckGeometry(selectedList[0]):
                self.geoToAttach = selectedList[0]
                cmds.textField(self.geoToAttachTF, edit=True, text=self.geoToAttach)
                self.dpLoadUVSet(self.geoToAttach)
        else:
            mel.eval("warning \"Select a geometry in order use it to attach rivets, please.\";") 
Example #7
Source File: dpBaseControlClass.py    From dpAutoRigSystem with GNU General Public License v2.0 6 votes vote down vote up
def doControlAction(self, destinationList, *args):
        """ Action to do when creating a control
            Do action as user wants:
                1 = New control
                2 = Add shape
                3 = Replace shapes
        """
        if self.cvAction == 1: #new control
            pass
        else:
            if destinationList:
                if self.cvAction == 2: #add shape
                    self.ctrls.transferShape(True, False, self.cvCurve, destinationList, True)
                elif self.cvAction == 3: #replace shapes
                    self.ctrls.transferShape(True, True, self.cvCurve, destinationList, True)
            else:
                cmds.delete(self.cvCurve)
                mel.eval("warning \""+self.langDic[self.langName]['e011_notSelShape']+"\";") 
Example #8
Source File: dpBaseClass.py    From dpAutoRigSystem with GNU General Public License v2.0 6 votes vote down vote up
def verifyGuideModuleIntegrity(self, *args):
        """ This function verify the integrity of the current module.
            Returns True if Ok and False if Fail.
        """
        # conditionals to be elegible as a rigged guide module:
        if cmds.objExists(self.moduleGrp):
            if cmds.objExists(self.moduleGrp+'.guideBase'):
                if cmds.getAttr(self.moduleGrp+'.guideBase') == 1:
                    return True
                else:
                    try:
                        self.deleteModule()
                        mel.eval('warning \"'+ self.langDic[self.langName]['e000_GuideNotFound'] +' - '+ self.moduleGrp +'\";')
                    except:
                        pass
                    return False 
Example #9
Source File: dispatcher.py    From spore with MIT License 6 votes vote down vote up
def global_reload():
    """ filter all loaded spore modules in the script dir and
    reload each of them. this is a convenience function for developing """

    import inspect

    windowed = mel.eval('$temp1=$gMainWindow')
    if windowed:
        scripts_dir = os.path.dirname(__file__)
        for key, module in sys.modules.iteritems():

            try:
                module_path = inspect.getfile(module)
            except TypeError:
                continue

            if module_path == __file__:
                continue

            if module_path.startswith(scripts_dir):
                reload(module) 
Example #10
Source File: dispatcher.py    From spore with MIT License 6 votes vote down vote up
def __init__(self):

        # set environment
        self.set_environment()

        # initialize global services
        self.spore_globals = settings.SporeGlobals()

        # initialize ui only in gui mode
        windowed = mel.eval('$temp1=$gMainWindow')
        if windowed:
            self.spore_manager = manager.SporeManager()
            self.spore_reporter = reporter.Reporter()

        #  self.spore_globals = self.parse_prefs()
        self.logger = self.get_logger()
        self.menu = self.build_menu()
        self.callbacks = self.add_callbacks()
        self.set_tracking_dir() 
Example #11
Source File: ui.py    From maya-channel-box-plus with GNU General Public License v3.0 6 votes vote down vote up
def getChannelBoxMenu():
    """
    Get ChannelBox, convert the main channel box to QT and return the QMenu 
    which is part of the channel box' children.

    :return: Maya's main channel box menu
    :rtype: QMenu
    """
    channelBox = getChannelBox()
    
    for child in channelBox.children():
        if type(child) == QMenu:
            cmd = "generateChannelMenu {0} 1".format(qtToMaya(child))
            mel.eval(cmd)
            return child


# ---------------------------------------------------------------------------- 
Example #12
Source File: capture.py    From maya-capture with MIT License 6 votes vote down vote up
def parse_active_scene():
    """Parse active scene for arguments for capture()

    *Resolution taken from render settings.

    """

    time_control = mel.eval("$gPlayBackSlider = $gPlayBackSlider")

    return {
        "start_frame": cmds.playbackOptions(minTime=True, query=True),
        "end_frame": cmds.playbackOptions(maxTime=True, query=True),
        "width": cmds.getAttr("defaultResolution.width"),
        "height": cmds.getAttr("defaultResolution.height"),
        "compression": cmds.optionVar(query="playblastCompression"),
        "filename": (cmds.optionVar(query="playblastFile")
                     if cmds.optionVar(query="playblastSaveToFile") else None),
        "format": cmds.optionVar(query="playblastFormat"),
        "off_screen": (True if cmds.optionVar(query="playblastOffscreen")
                       else False),
        "show_ornaments": (True if cmds.optionVar(query="playblastShowOrnaments")
                       else False),
        "quality": cmds.optionVar(query="playblastQuality"),
        "sound": cmds.timeControl(time_control, q=True, sound=True) or None
    } 
Example #13
Source File: install.py    From maya-skinning-tools with GNU General Public License v3.0 6 votes vote down vote up
def shelf():
    """
    Add a new shelf in Maya with all the tools that are provided in the
    SHELF_TOOLS variable. If the tab exists it will be deleted and re-created
    from scratch.
    """
    # get top shelf
    gShelfTopLevel = mel.eval("$tmpVar=$gShelfTopLevel")

    # get top shelf names
    shelves = cmds.tabLayout(gShelfTopLevel, query=1, ca=1)
    
    # delete shelf if it exists
    if SHELF_NAME in shelves:
        cmds.deleteUI(SHELF_NAME)

    # create shelf
    cmds.shelfLayout(SHELF_NAME, parent=gShelfTopLevel)
    
    # add modules
    for tool in SHELF_TOOLS:
        if tool.get("image1"):
            cmds.shelfButton(style="iconOnly", parent=SHELF_NAME, **tool)
        else:
            cmds.shelfButton(style="textOnly", parent=SHELF_NAME, **tool) 
Example #14
Source File: progress.py    From maya-skinning-tools with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, total, message=None):
        # set numeration variables
        self._value = 0
        self._total = total
        self._message = message

        # get progress bar
        self._bar = None
        self._batch = cmds.about(batch=True)

        if not self._batch:
            self._bar = mel.eval("$tmp = $gMainProgressBar")
            cmds.progressBar(
                self._bar,
                edit=True,
                isInterruptable=False,
                status=self.message,
                minValue=0,
                maxValue=total
            ) 
Example #15
Source File: EditMesh.py    From rush with MIT License 5 votes vote down vote up
def polyFlip():
    mel.eval("dR_performSymmetryFlip") 
Example #16
Source File: modify.py    From rush with MIT License 5 votes vote down vote up
def stackUVShells():
    mel.eval("texStackShells;") 
Example #17
Source File: modify.py    From rush with MIT License 5 votes vote down vote up
def snapAndStackUVs():
    mel.eval("texSnapStackShells;") 
Example #18
Source File: modify.py    From rush with MIT License 5 votes vote down vote up
def orientUVShellsToEdges():
    mel.eval("texOrientEdge;") 
Example #19
Source File: Modify.py    From rush with MIT License 5 votes vote down vote up
def textureToGeometryOptions():
    mel.eval("""performTextureToGeom 1""") 
Example #20
Source File: Modify.py    From rush with MIT License 5 votes vote down vote up
def searchReplaceNames():
    mel.eval("performSearchReplaceNames 1") 
Example #21
Source File: Modify.py    From rush with MIT License 5 votes vote down vote up
def alignTool():
    mel.eval("setToolTo alignToolCtx") 
Example #22
Source File: Modify.py    From rush with MIT License 5 votes vote down vote up
def performAlignObjects():
    cmds.perform
    mel.eval("performAlignObjects 0") 
Example #23
Source File: Windows.py    From rush with MIT License 5 votes vote down vote up
def customStereoRigEditorWindow():
    mel.eval("""stereoCameraCBwrapper("stereoRigToolEditor","customRigEditor()")""") 
Example #24
Source File: uExport.py    From uExport with zlib License 5 votes vote down vote up
def setOutlinerToShowAssetContents(self):
        mel.eval('outlinerEditor -e -showContainerContents 1 outlinerPanel1; outlinerEditor -e \
        -showContainedOnly 0 outlinerPanel1;') 
Example #25
Source File: dm2skin.py    From dm2skin with The Unlicense 5 votes vote down vote up
def dm2skin_getMaxInfluences(mesh):
    """Finds a skin cluster on the given mesh and returns
    the number of influences it is set to have."""
    skinClusterStr = 'findRelatedSkinCluster("' + mesh + '")'
    skinCluster = mel.eval(skinClusterStr)
    if not skinCluster:
        return 0
    allInfluences = cmds.skinCluster(skinCluster, q=True, inf=True)
    return len(allInfluences) 
Example #26
Source File: mayascene.py    From cross3d with MIT License 5 votes vote down vote up
def importFBX(self, path, **kwargs):

		# TODO: Softimage returns a model. Here we return a boolean. Do we want to make imported FBX into models or maybe return a list of objects?
		args = { 'animation':True, 
				 'cameras':True,
				 'lights':True,
				 'envelopes':True,
				 'forceNormEnvelope':False,
				 'keepXSIEffectors':True,
				 'skeletonsAsNulls':True,
				 'scaleFactor':1.0,
				 'axisConversion':True,
				 'fillTimeline':True,
				 'scaleConversion': False,
				 'converUnit': 'cm' }

		args.update(kwargs)

		# TODO: We could handle way more options.
		mel.eval('loadPlugin -quiet "fbxmaya.mll"')
		mel.eval('FBXImportSkins -v %s' % unicode(args['envelopes']).lower())
		mel.eval('FBXImportCameras -v %s' % unicode(args['cameras']).lower())
		mel.eval('FBXImportLights -v %s' % unicode(args['lights']).lower())
		mel.eval('FBXImportFillTimeline -v %s' % unicode(args['fillTimeline']).lower())
		mel.eval('FBXImportSkeletonDefinitionsAs -v "humanik"')
		mel.eval('FBXImportAxisConversionEnable -v %s' % unicode(args['axisConversion']).lower())

		if os.path.exists(path):
			mel.eval('FBXImport -f "%s" -t -1' % os.path.normpath(path).replace('\\', '\\\\'))
			return True
		return False 
Example #27
Source File: languages.py    From hotbox_designer with BSD 3-Clause Clear License 5 votes vote down vote up
def execute_mel(code):
    from maya import mel
    mel.eval(code.replace(u'\u2029', '\n')) 
Example #28
Source File: utils.py    From maya-command-search with GNU General Public License v3.0 5 votes vote down vote up
def getStatusLine():
    """
    Get the QWidget of Maya's status line. 
    
    :return: QWidget of Maya's status line
    :rtype: QWidget
    """
    gStatusLine = mel.eval("$tmpVar=$gStatusLine")
    return mayaToQT(gStatusLine)

# ---------------------------------------------------------------------------- 
Example #29
Source File: test_performance.py    From cmdx with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_createNode_performance():
    """createNode cmdx vs cmds > 2x"""

    versions = (
        ("mel", lambda: mel.eval("createNode \"transform\"")),
        ("cmds", lambda: cmds.createNode("transform")),
        ("cmdx", lambda: cmdx.createNode(cmdx.tTransform)),
        # ("PyMEL", lambda: pm.createNode("transform")),
        ("API 1.0", lambda: om1.MFnDagNode().create("transform")),
        ("API 2.0", lambda: om2.MFnDagNode().create("transform")),
    )

    for contender, test in versions:
        Compare(contender, "createNode", test, setup=New)

    cmdx_vs_cmds = (
        timings["createNode"]["cmds"]["percall"] /
        timings["createNode"]["cmdx"]["percall"]
    )

    cmdx_vs_api = (
        timings["createNode"]["API 2.0"]["percall"] /
        timings["createNode"]["cmdx"]["percall"]
    )

    assert_greater(cmdx_vs_cmds, 0.5)  # at most 2x slower than cmds
    assert_greater(cmdx_vs_api, 0.20)  # at most 5x slower than API 2.0 
Example #30
Source File: modify.py    From rush with MIT License 5 votes vote down vote up
def stackUVShells():
    mel.eval("texStackShells;")