TransWikia.com

How do I tell python to ignore a certain specified bone when it is not present in the armature

Blender Asked by RiotingSpectre on November 17, 2021

I am writing a script to certain bones inside of an armature.
But if the script cannot find one of the bones I have specified the whole script just dies out and doesn’t run any further. how can I make it so that if the script can’t find a bone it ignores that bone and goes onto the next line of code.

One Answer

You can use try statement in Python script. See the document here.

A simple script:

a_list = [1,0,2,3,4,5]
result_list = []
while a_list:
    try: # Try to run this block
        divider = a_list[-1]
        result = 60 / divider
        result_list.append(result)
    except: # if "any" Error happen, do this block
        print(f"Oops, something go wrong: divider:{divider}")
        break
    finally: # whether there is an error or what, run this block
        a_list.pop()
result_list

Output:

Oops, something go wrong: divider:0
[12.0, 15.0, 20.0, 30.0]

Please don't silently bypass an error in code, let user know what happens and if possible, let them decide what to do explicit.

Answered by HikariTW on November 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP