Python maya.cmds.refresh() Examples

The following are 10 code examples of maya.cmds.refresh(). 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: lib.py    From core with MIT License 5 votes vote down vote up
def suspended_refresh():
    """Suspend viewport refreshes"""

    try:
        cmds.refresh(suspend=True)
        yield
    finally:
        cmds.refresh(suspend=False) 
Example #2
Source File: progress_bar.py    From spore with MIT License 5 votes vote down vote up
def run(self):
        # cmds.waitCursor(status=1)
        cmds.progressBar(self._progress_bar,
                         e=1,
                         bp=1,
                         ii=self._interruptable,
                         status=self._status,
                         min=self._start,
                         max=self._end
                         )
        cmds.refresh() 
Example #3
Source File: interop.py    From P4VFX with MIT License 5 votes vote down vote up
def refresh():
        cmds.refresh() 
Example #4
Source File: interop.py    From P4VFX with MIT License 5 votes vote down vote up
def refresh():
        cmds.refresh() 
Example #5
Source File: ml_pivot.py    From ml_tools with MIT License 5 votes vote down vote up
def doEditPivotDriver(self, *args):

        newValue = mc.floatSliderButtonGrp(self.floatSlider, query=True, value=True)
        try:
            mc.deleteUI(self.pivotDriverWindow)
        except:
            pass

        currentValue = mc.getAttr(self.pivotDriver)
        if newValue == currentValue:
            return

        oldRP = mc.getAttr(self.node+'.rotatePivot')[0]
        mc.setAttr(self.pivotDriver, newValue)
        newRP = mc.getAttr(self.node+'.rotatePivot')[0]
        mc.setAttr(self.pivotDriver, currentValue)

        parentPosition = mc.group(em=True)
        offsetPosition = mc.group(em=True)
        offsetPosition = mc.parent(offsetPosition, parentPosition)[0]
        mc.setAttr(offsetPosition+'.translate', newRP[0]-oldRP[0], newRP[1]-oldRP[1], newRP[2]-oldRP[2])

        mc.delete(mc.parentConstraint(self.node, parentPosition))

        utl.matchBake(source=[self.node], destination=[parentPosition], bakeOnOnes=True, maintainOffset=False, preserveTangentWeight=False)

        mc.cutKey(self.pivotDriver)
        mc.setAttr(self.pivotDriver, newValue)
        mc.refresh()
        utl.matchBake(source=[offsetPosition], destination=[self.node], bakeOnOnes=True, maintainOffset=False, preserveTangentWeight=False, rotate=False)

        mc.delete(parentPosition) 
Example #6
Source File: ml_utilities.py    From ml_tools with MIT License 5 votes vote down vote up
def drag(self, *args):
        '''
        This is what is actually run during the drag, updating the coordinates and calling the
        placeholder drag functions depending on which button is pressed.
        '''

        self.dragPoint = mc.draggerContext(self.draggerContext, query=True, dragPoint=True)

        #if this doesn't work, try getmodifier
        self.modifier = mc.draggerContext(self.draggerContext, query=True, modifier=True)

        self.x = ((self.dragPoint[0] - self.anchorPoint[0]) * self.multiplier) + self.defaultValue
        self.y = ((self.dragPoint[1] - self.anchorPoint[1]) * self.multiplier) + self.defaultValue

        if self.minValue is not None and self.x < self.minValue:
            self.x = self.minValue
        if self.maxValue is not None and self.x > self.maxValue:
            self.x = self.maxValue

        #dragString
        if self.modifier == 'control':
            if self.button == 1:
                self.dragControlLeft(*args)
            elif self.button == 2:
                self.dragControlMiddle(*args)
        elif self.modifier == 'shift':
            if self.button == 1:
                self.dragShiftLeft(*args)
            elif self.button == 2:
                self.dragShiftMiddle(*args)
        else:
            if self.button == 1:
                self.dragLeft()
            elif self.button == 2:
                self.dragMiddle()

        mc.refresh() 
Example #7
Source File: capture.py    From pyblish-bumpybox with GNU Lesser General Public License v3.0 4 votes vote down vote up
def _independent_panel(width, height, off_screen=False):
    """Create capture-window context without decorations

    Arguments:
        width (int): Width of panel
        height (int): Height of panel

    Example:
        >>> with _independent_panel(800, 600):
        ...   cmds.capture()

    """

    # center panel on screen
    screen_width, screen_height = _get_screen_size()
    topLeft = [int((screen_height-height)/2.0),
               int((screen_width-width)/2.0)]

    window = cmds.window(width=width,
                         height=height,
                         topLeftCorner=topLeft,
                         menuBarVisible=False,
                         titleBar=False,
                         visible=not off_screen)
    cmds.paneLayout()
    panel = cmds.modelPanel(menuBarVisible=False,
                            label='CapturePanel')

    # Hide icons under panel menus
    bar_layout = cmds.modelPanel(panel, q=True, barLayout=True)
    cmds.frameLayout(bar_layout, edit=True, collapse=True)

    if not off_screen:
        cmds.showWindow(window)

    # Set the modelEditor of the modelPanel as the active view so it takes
    # the playback focus. Does seem redundant with the `refresh` added in.
    editor = cmds.modelPanel(panel, query=True, modelEditor=True)
    cmds.modelEditor(editor, edit=True, activeView=True)

    # Force a draw refresh of Maya so it keeps focus on the new panel
    # This focus is required to force preview playback in the independent panel
    cmds.refresh(force=True)

    try:
        yield panel
    finally:
        # Delete the panel to fix memory leak (about 5 mb per capture)
        cmds.deleteUI(panel, panel=True)
        cmds.deleteUI(window) 
Example #8
Source File: capture.py    From maya-capture with MIT License 4 votes vote down vote up
def _independent_panel(width, height, off_screen=False):
    """Create capture-window context without decorations

    Arguments:
        width (int): Width of panel
        height (int): Height of panel

    Example:
        >>> with _independent_panel(800, 600):
        ...   cmds.capture()

    """

    # center panel on screen
    screen_width, screen_height = _get_screen_size()
    topLeft = [int((screen_height-height)/2.0),
               int((screen_width-width)/2.0)]

    window = cmds.window(width=width,
                         height=height,
                         topLeftCorner=topLeft,
                         menuBarVisible=False,
                         titleBar=False,
                         visible=not off_screen)
    cmds.paneLayout()
    panel = cmds.modelPanel(menuBarVisible=False,
                            label='CapturePanel')

    # Hide icons under panel menus
    bar_layout = cmds.modelPanel(panel, q=True, barLayout=True)
    cmds.frameLayout(bar_layout, edit=True, collapse=True)

    if not off_screen:
        cmds.showWindow(window)

    # Set the modelEditor of the modelPanel as the active view so it takes
    # the playback focus. Does seem redundant with the `refresh` added in.
    editor = cmds.modelPanel(panel, query=True, modelEditor=True)
    cmds.modelEditor(editor, edit=True, activeView=True)

    # Force a draw refresh of Maya so it keeps focus on the new panel
    # This focus is required to force preview playback in the independent panel
    cmds.refresh(force=True)

    try:
        yield panel
    finally:
        # Delete the panel to fix memory leak (about 5 mb per capture)
        cmds.deleteUI(panel, panel=True)
        cmds.deleteUI(window) 
Example #9
Source File: ml_pivot.py    From ml_tools with MIT License 4 votes vote down vote up
def reset_pivot(*args):

    sel = mc.ls(sl=True)
    if not sel:
        om.MGlobal.displayWarning('Nothing selected.')
        return

    if len(sel) > 1:
        om.MGlobal.displayWarning('Only works on one node at a time.')
        return

    node = sel[0]
    driver = None
    driver_value = None
    driver_default = None

    if is_pivot_connected(node):
        driver = pivot_driver_attr(node)
        if driver:
            dNode,dAttr = driver.split('.',1)
            driver_value = mc.getAttr(driver)
            driver_default = mc.attributeQuery(dAttr, node=dNode, listDefault=True)[0]
            if driver_default == driver_value:
                return
        else:
            om.MGlobal.displayWarning('Pivot attribute is connected, unable to edit.')
            return

    if not driver:
        pivotPosition = mc.getAttr(node+'.rotatePivot')[0]
        if pivotPosition  == (0.0,0.0,0.0):
            return

    tempPosition = mc.group(em=True)
    tempPivot = mc.group(em=True)
    tempPivot = mc.parent(tempPivot, node)[0]
    if driver:
        mc.setAttr(driver, driver_default)
        newRP = mc.getAttr(node+'.rotatePivot')[0]
        mc.setAttr(driver, driver_value)
        mc.setAttr(tempPivot+'.translate', *newRP)
    else:
        mc.setAttr(tempPivot+'.translate', 0,0,0)

    mc.setAttr(tempPivot+'.rotate', 0,0,0)

    utl.matchBake(source=[tempPivot], destination=[tempPosition], bakeOnOnes=True, maintainOffset=False, preserveTangentWeight=False, rotate=False)

    if driver:
        mc.setAttr(driver, driver_default)
    else:
        mc.setAttr(node+'.rotatePivot', 0,0,0)

    mc.refresh()
    utl.matchBake(source=[tempPosition], destination=[node], bakeOnOnes=True, maintainOffset=False, preserveTangentWeight=False, rotate=False)

    mc.delete(tempPosition,tempPivot)

    mc.select(node) 
Example #10
Source File: ml_centerOfMass.py    From ml_tools with MIT License 4 votes vote down vote up
def createCenterOfMass(*args):
    '''
    Create a center of mass node, and constrain it to the
    character based on the selected root node.
    '''

    sel = mc.ls(sl=True)

    if not len(sel) == 1:
        raise RuntimeError('Please select the root control of your puppet.')

    print 'Create Center Of Mass Node'
    print '--------------------------'

    meshes = meshesFromReference(sel[0]) or meshesFromHistory(sel[0])

    if not meshes:
        raise RuntimeError('Could not determine geometry from selected control. Make sure geo is visible.')

    mc.select(meshes)
    mc.refresh()

    print 'Discovered Meshes:'
    for mesh in meshes:
        print '\t',mesh

    skinnedMeshes = []
    for mesh in meshes:
        if utl.getSkinCluster(mesh):
            skinnedMeshes.append(mesh)
            continue
        hist = mc.listHistory(mesh, breadthFirst=True)
        skins = mc.ls(hist, type='skinCluster')
        if not skins:
            warnings.warn('Could not find a skinned mesh affecting {}'.format(mesh))
            continue
        outGeo = mc.listConnections(skins[0]+'.outputGeometry[0]', source=False)
        outGeo = mc.ls(outGeo, type=['mesh','transform'])
        if not outGeo:
            warnings.warn('Could not find a skinned mesh affecting {}'.format(mesh))
            continue
        skinnedMeshes.append(outGeo[0])

    if not skinnedMeshes:
        raise RuntimeError('Could not determine skinned geometry from selected control. This tool will only work if geo is skinned.')

    locator = centerOfMassLocator(skinnedMeshes)

    mc.addAttr(locator, longName=COM_ATTR, attributeType='message')
    mc.connectAttr('.'.join((sel[0],'message')), '.'.join((locator,COM_ATTR)))

    mc.select(sel)
    return locator