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.
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
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP