Forum: Poser Python Scripting


Subject: Useful Code Snippets

structure opened this issue on Jun 27, 2019 ยท 94 posts


adp001 posted Wed, 03 November 2021 at 2:31 AM

Not so seldom we have situations in which an occurring error is tollerable. Typically we wrap such a situation in a try/except clause.

But this can also be done differently, if we use an appropriate class:


class ignore_error(object):
def __init__(self):
pass

def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
return True


Now we can write:


with ignore_error():
actor = poser.Scene().Actor("not existing actor")

without causing an error.

Note that the entire block after "ignore_error" is ignored in case of an error. Like the part that follows a "try".