i need to debug a script in blender
and wondering if there is some command i can add in my script like
a stop or pause ?
so that it does not crash blender and i can still check the console to see what has been printed
i tried the os exist but this crash blender
so cannot analyse the console’s data
thanks
happy bl
KDLynch
(Kelly Lynch)
June 23, 2023, 4:10pm
2
have you tried raise.exception(‘stopping here’) ?
1 Like
Mark other part as comment? “”"
raise.exception(‘stopping here 1 ’))
does this one should work in 2.79 and BL 3.6 ?
in 2.79 and bl 3.6 i get error on that line ?
thanks
happy bl
KDLynch
(Kelly Lynch)
June 23, 2023, 5:13pm
6
i ran it in 3.5… and yes, it does cause an error on that line, that’s it’s job, once the code reaches that point, stopping your script right there, >without< crashing blender (like quit() etc would do)
needed to change how it is written
raise Exception(' Stop here 2 ' )
that works well in 2.79 will check in BL 3.6
thanks
happy bl
1 Like
KDLynch
(Kelly Lynch)
June 23, 2023, 5:20pm
8
rolf… i didn’t catch i had a . between raise and exception… my bad. yeah, no dot notation needed.
just use vscode and set a breakpoint where you want it to stop… that’s literally the entire point of using a debugger.
i know
i’v use some IDE thing a few years back in older BL version
but got use to simply use the console to debug my relatively simple scripts
thanks for suggestion
happy bl
Maybe this tip from the Blender Python API documentation will help
https://docs.blender.org/api/3.5/info_tips_and_tricks.html#insert-a-python-interpreter-into-your-script
In the middle of a script you may want to inspect variables, run functions and inspect the flow.
import code
code.interact(local=locals())
If you want to access both global and local variables run this:
import code
namespace = globals().copy()
namespace.update(locals())
code.interact(local=namespace)
The next example is an equivalent single line version of the script above which is easier to paste into your code:
__import__('code').interact(local=dict(globals(), **locals()))
code.interact
can be added at any line in the script and will pause the script to launch an interactive interpreter in the terminal, when you’re done you can quit the interpreter and the script will continue execution.