Stop a script at a certain line?

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

have you tried raise.exception(‘stopping here’) ? :slight_smile:

1 Like

Mark other part as comment? “”"

  1. Use the vscode Blender addon, in which case you can use vscode debugger.
  2. Use logging.
2 Likes

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

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

rolf… i didn’t catch i had a . between raise and exception… my bad. :slight_smile: 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.