logging vs print

It’s extremely useful to add print statements to our code, so we can track down the progress and variables as the code run.
But it get’s dirty and hard to read when lots of print lines run from multiple scripts.

That’s where python built-in logging module comes to the rescue!
in a nut shell, this module is thread safe, supports logging to stdout/shell, files, emails, http and over network.
Check out logging documentation for more: http://docs.python.org/release/2.7/library/logging.html

Where it’s come really useful is when you need to communicate an error or a message so it won’t get lost!
In some cases you would want to log directly into an email or into s log-file to keep track.
What ever the case is, logging can do it with it’s built-in handlers.

I started cgLogger, an OpenSource wrapper over the build-in logging module, that supports logging in Nuke and Maya using their native commands. This takes advantage of logging messages in a way that will get the artists attention ( or at less more likely to do so ). In many cases it’s very to communicate warning/errors out to the end-user. There for the cgLogger will raise a messageBox for level ERROR and CRITICAL to make sure we have end-user attention.

Code in GitHub:https://github.com/asisudai/cg-logging
This code was inspired by Alex Segal. Thank you Alex.

QTreeWidget with custom QTreeWidgetItem

Often it’s needed to represent items in a row, where each row can have widgets related to it.
In this example we’ll create QTreeWidgetItem with a QSpinBox and QPushButton for each row.

This is a basic example, but can have many uses.


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.