Python maya.cmds.currentUnit() Examples

The following are 12 code examples of maya.cmds.currentUnit(). 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.cmds , or try the search function .
Example #1
Source File: ml_utilities.py    From ml_tools with MIT License 8 votes vote down vote up
def getFrameRate():
    '''
    Return an int of the current frame rate
    '''
    currentUnit = mc.currentUnit(query=True, time=True)
    if currentUnit == 'film':
        return 24
    if currentUnit == 'show':
        return 48
    if currentUnit == 'pal':
        return 25
    if currentUnit == 'ntsc':
        return 30
    if currentUnit == 'palf':
        return 50
    if currentUnit == 'ntscf':
        return 60
    if 'fps' in currentUnit:
        return int(currentUnit.substitute('fps',''))

    return 1 
Example #2
Source File: ml_utilities.py    From ml_tools with MIT License 6 votes vote down vote up
def getDistanceInMeters():

    unit = mc.currentUnit(query=True, linear=True)

    if unit == 'mm':
        return 1000
    elif unit == 'cm':
        return 100
    elif unit == 'km':
        return 0.001
    elif unit == 'in':
        return 39.3701
    elif unit == 'ft':
        return 3.28084
    elif unit == 'yd':
        return 1.09361
    elif unit == 'mi':
        return 0.000621371

    return 1 
Example #3
Source File: dpControls.py    From dpAutoRigSystem with GNU General Public License v2.0 5 votes vote down vote up
def dpCheckLinearUnit(self, origRadius, defaultUnit="centimeter", *args):
        """ Verify if the Maya linear unit is in Centimeter.
            Return the radius to the new unit size.

            WIP!
            Changing to shapeSize cluster setup
        """
        newRadius = origRadius
    #    newRadius = 1
    #    linearUnit = cmds.currentUnit(query=True, linear=True, fullName=True)
    #    # centimeter
    #    if linearUnit == defaultUnit:
    #        newRadius = origRadius
    #    elif linearUnit == "meter":
    #        newRadius = origRadius*0.01
    #    elif linearUnit == "millimeter":
    #        newRadius = origRadius*10
    #    elif linearUnit == "inch":
    #        newRadius = origRadius*0.393701
    #    elif linearUnit == "foot":
    #        newRadius = origRadius*0.032808
    #    elif linearUnit == "yard":
    #        newRadius = origRadius*0.010936
        return newRadius
    
    
    #@utils.profiler 
Example #4
Source File: maya_warpper.py    From pipeline with MIT License 5 votes vote down vote up
def set_fps(fps = None):
    fps_string = "pal"
    if fps == 25:
        fps_string = "pal"
    if fps == 24:
        fps_string = "film"
    if fps == 30:
        fps_string = "ntsc"                
    cmds.currentUnit(t=fps_string) 
Example #5
Source File: ViewportPainter.py    From mViewportDrawOpenGL with MIT License 5 votes vote down vote up
def initializeGL(self):

        #scene measure units
        unit = cmds.currentUnit(q=1, linear=1)
        if unit == "m":
            self.unit = float(self.unit) * 100.0

        self.glFT = OpenMayaRender.MHardwareRenderer.theRenderer().glFunctionTable() 
Example #6
Source File: BlendTransforms.py    From BlendTransforms with The Unlicense 5 votes vote down vote up
def BT_SetUnits():
    if cmds.currentUnit(q = True, linear = True) != "cm":
        cmds.currentUnit(linear = "cm")
        return True
    return False 
Example #7
Source File: BlendTransforms.py    From BlendTransforms with The Unlicense 5 votes vote down vote up
def BT_SetUnits():
    if cmds.currentUnit(q = True, linear = True) != "cm":
        cmds.currentUnit(linear = "cm")
        return True
    return False 
Example #8
Source File: BlendTransforms.py    From BlendTransforms with The Unlicense 5 votes vote down vote up
def BT_SetUnits():
    if cmds.currentUnit(q = True, linear = True) != "cm":
        cmds.currentUnit(linear = "cm")
        return True
    return False 
Example #9
Source File: BlendTransforms.py    From BlendTransforms with The Unlicense 5 votes vote down vote up
def BT_SetUnits():
    if cmds.currentUnit(q = True, linear = True) != "cm":
        cmds.currentUnit(linear = "cm")
        return True
    return False 
Example #10
Source File: mayascene.py    From cross3d with MIT License 5 votes vote down vote up
def _currentTimeUnit(cls):
		""" Returns the current time unit name. See MayaScene._timeUnitToFPS to map this value
		to real world fps.
		:return: The name of the current fps
		"""
		return cmds.currentUnit(q=True, time=True) 
Example #11
Source File: mayascene.py    From cross3d with MIT License 5 votes vote down vote up
def setAnimationFPS(self, fps, changeType=constants.FPSChangeType.Seconds, callback=None):
		""" Updates the scene's fps to the provided value and scales existing keys as specified.
		StudioMax Note: If you have any code that you need to run after changing the fps and plan to use it in
			3dsMax you will need to pass that code into the callback argument.
		Maya Note: Maya only supports specific fps settings. If you provide it with a value it doesn't understand,
			it will be set to the closest matching value. See MayaScene._timeUnitToFPS for valid values.
		:param fps: The FPS value to set.
		:param changeType: <constants.FPSChangeType> Defaults to constants.FPSChangeType.Frames
		:param callback: <funciton> Code called after the fps is changed.
		:return: bool success
		"""
		# Maya doesn't appear to allow you to set the fps to a specific value,
		# so we attempt to find a exact match in our _timeUnitToConst dictonary
		name = self._timeUnitToConst.get(fps)
		if not name:
			# If there isn't a exact match, find the value closest to the requested fps.
			closest = min(self._timeUnitToConst, key=lambda x: abs(x - fps))
			name = self._timeUnitToConst[closest]
		# Only update the fps if the value is different
		if name != self._currentTimeUnit():
			# Only update animation if Seconds is specified
			updateAnimation = changeType == constants.FPSChangeType.Seconds
			cmds.currentUnit(time=name, updateAnimation=updateAnimation)
		if callback:
			callback()
		return True 
Example #12
Source File: commands.py    From core with MIT License 4 votes vote down vote up
def reset_frame_range():
    """Set frame range to current asset"""
    shot = api.Session["AVALON_ASSET"]
    shot = io.find_one({"name": shot, "type": "asset"})

    try:

        frame_start = shot["data"].get(
            "frameStart",
            # backwards compatibility
            shot["data"].get("edit_in")
        )
        frame_end = shot["data"].get(
            "frameEnd",
            # backwards compatibility
            shot["data"].get("edit_out")
        )
    except KeyError:
        cmds.warning("No edit information found for %s" % shot["name"])
        return

    fps = {15: 'game',
           24: 'film',
           25: 'pal',
           30: 'ntsc',
           48: 'show',
           50: 'palf',
           60: 'ntscf',
           23.98: '23.976fps',
           23.976: '23.976fps',
           29.97: '29.97fps',
           47.952: '47.952fps',
           47.95: '47.952fps',
           59.94: '59.94fps',
           44100: '44100fps',
           48000: '48000fps'
           }.get(float(api.Session.get("AVALON_FPS", 25)), "pal")

    cmds.currentUnit(time=fps)

    cmds.playbackOptions(minTime=frame_start)
    cmds.playbackOptions(maxTime=frame_end)
    cmds.playbackOptions(animationStartTime=frame_start)
    cmds.playbackOptions(animationEndTime=frame_end)
    cmds.playbackOptions(minTime=frame_start)
    cmds.playbackOptions(maxTime=frame_end)
    cmds.currentTime(frame_start)