Disable maya viewport while running code

How to disable maya viewport while running a bake or export process?
I couldn’t remember what’s the ui object name that controls Maya viewport.

Today I looked online for that little code snippet and could find it.
I felt so frustrated that it drove me to start this blog 🙂

So here we go.

When running a process that loops through the scene frames, like bake animation or export geo,
Maya will update the viewport per frame. This update is redundant and will slow the process down.
So to avoid that, we can turn off the viewport while the code is running.

2 thoughts on “Disable maya viewport while running code

  1. Hello,

    I just stumbled upon your blog.

    I think you should use a finally clause instead of duplicating code.

    mel.eval(“paneLayout -e -manage true $gMainPane”)

    Moreover, you should use functools.wraps in your decorator.

    An finally, a full function that accepts any parameter has the following signature
    def func(*args, **kwargs):


  2. Hiya. Thanks for this – saves me a ton of time. However, if I ever need to undo the called function, the viewportRefresh doesn’t get called, and it’s often a slow process. Is there a way around this?

    Sorry if the answer is obvious – I don’t code all that much. Thanks so much!

Leave a Reply

Your email address will not be published. Required fields are marked *

Captcha! *