I've found there are times when it's convenient to silence the pymel logger
with a context manager.  One example would be getting the names of nodes
that were deleted *after* they were deleted.  The problem is that node.name()
 will still return the name, but warn that the node doesn't exist.

One caveat is that there is no promise that the name of the Pymel logger
won't change.  Pymel seems fairly mature though, and I'd imagine a package
re-organization would warrant a new major version.

class SilencePymelLogger(object):    def __init__(self):
self.level = 10        self.pmLogger =
logging.getLogger('pymel.core.nodetypes')

    def __enter__(self):        self.pmLogger.propagate = 0
self.level = self.pmLogger.level        self.pmLogger.setLevel(50)
   return self

    def __exit__(self, exctype, excval, exctb):
self.pmLogger.propagate = 1        self.pmLogger.setLevel(self.level)




from __future__ import with_statement


with SilencePymelLogger():


    #do stuff



-JP


On Thu, Jun 28, 2012 at 12:42 PM, Chad Dombrova <[email protected]> wrote:

> that error should only occur when something tries to operate on one of
> those PyNodes. so in the relevant code, you could add a .exists() check
> before doing so.  additionally, you could look into MSceneMessage, which
> provides more fine grained control over scene callbacks, like kBeforeOpen
> and kAfterOpen.
>
> -chad
>
>
>
>
>
> On Thu, Jun 28, 2012 at 12:12 PM, hapgilmore <[email protected]>wrote:
>
>> I have a class that tracks and manages certain nodes in a scene. When the
>> scene is unloaded, all of the PyNodes that were being tracked become
>> invalid, and pymel prints a warning for every one:
>> # Warning: pymel.core.nodetypes : object foo no longer exists #
>> # Warning: pymel.core.nodetypes : object foo1 no longer exists #
>> # Warning: pymel.core.nodetypes : object foo2 no longer exists #
>>
>> The problem is this list can be a thousand nodes long, so every time I
>> close a file, maya takes 10 seconds to print all the warnings.
>> The 'deleteAll' event for scriptJobs is triggered too late for me to
>> clean up the PyNodes before the maya nodes are deleted.
>>
>> Is there another way to trigger a cleanup before the scene is unloaded?
>> Or at a minimum suppress the # Warning spew?
>>
>> --
>> view archives: http://groups.google.com/group/python_inside_maya
>> change your subscription settings:
>> http://groups.google.com/group/python_inside_maya/subscribe
>>
>
>  --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings:
> http://groups.google.com/group/python_inside_maya/subscribe
>



-- 
John Patrick
404-242-2675
[email protected]
http://www.canyourigit.com

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe

Reply via email to