Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable refresh on publish #86

Closed
mottosso opened this issue Mar 15, 2017 · 4 comments
Closed

Disable refresh on publish #86

mottosso opened this issue Mar 15, 2017 · 4 comments

Comments

@mottosso
Copy link
Contributor

Goal

Optimise publishing.

Motivation

Exporting animations can sometimes take longer than necessary due to viewport updates.

@BigRoy
Copy link
Collaborator

BigRoy commented Mar 20, 2017

Here are some context managers that can help:

import contextlib
import logging
import maya.cmds as mc
import maya.mel as mel

log = logging.getLogger(__name__)


def _get_mel_global(name):
    """Return the value of a mel global variable"""
    return mel.eval("$%s = $%s;" % (name, name))


@contextlib.contextmanager
def suspend_refresh():
    """Suspend viewport refreshes"""

    try:
        mc.refresh(suspend=True)
        yield
    finally:
        mc.refresh(suspend=False)


@contextlib.contextmanager
def no_panel_refresh():
    """Disable all controlled panel refreshes."""
    controls = list()
    for panel in mc.lsUI(panels=True, long=True):

        control = mc.panel(panel, query=True, control=True)
        if not control:
            continue

        if not mc.layout(control, query=True, visible=True):
            continue

        controls.append(control)

    try:

        for control in controls:
            mc.layout(control, edit=True, manage=False)
        yield

    finally:
        for control in controls:
            try:
                mc.layout(control, edit=True, manage=True)
            except RuntimeError:
                log.warning("Can't manage control {0}".format(control))


@contextlib.contextmanager
def no_refresh():
    """Temporarily disables Maya's UI updates

    Note:
        This only disabled the main pane and will sometimes still
        trigger updates in torn off panels.

    """

    pane = _get_mel_global('gMainPane')
    state = mc.paneLayout(pane, q=1, manage=1)
    mc.paneLayout(pane, e=1, manage=False)

    try:
        yield
    finally:
        mc.paneLayout(pane, e=1, manage=state)

Example usage:

with no_refresh():
    # do something here
    print "Work!"

I tend to use no_refresh a lot, though I believe separated viewport panels still continue to update. Last time I checked suspend_refresh didn't do as much speedup as the others.

@mottosso
Copy link
Contributor Author

Neat, haven't seen nor used the panel suspenders before.

Personally, I would call each context manager an adjective.

with refresh_suspended():
with panels_suspended():
with main_pane_suspended():

mottosso added a commit to mindbender-studio/config that referenced this issue Jun 16, 2017
@tokejepsen
Copy link
Collaborator

This seems to have been implemented?

@mottosso
Copy link
Contributor Author

mottosso commented Jun 7, 2018

Indeed!

@mottosso mottosso closed this as completed Jun 7, 2018
antirotor pushed a commit to antirotor/core that referenced this issue Apr 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants