serhii.net

In the middle of the desert you can say anything you want

10 Sep 2024

3D Slicer reloading a scriptedCLI module

EDIT: this may be all wrong, in the debugger I can just edit the code and it gets automatically used by slicer — logical, since it’s just a CLI script.

It’s the .xml with the interface that’s problematic and it can’t be reloaded using the method below, or at least I couldn’t.


A scriptedcli module imported to Slicer doesn’t show for me the usual “reload” buttons as seen in scripted modules in dev. mode. To develop, I need my changes I need to reload it w/o restarting 3dslicer.

Based on this more complete example1 linked in the script repository2

>>> mpath = "/full/path/to/the/my_module.py"
>>> factoryManager = slicer.app.moduleManager().factoryManager()
>>> factoryManager.registerModule(qt.QFileInfo(mpath))
>>> factoryManager.loadModules(["my_module"])
True

BONUS:

  • To debug such a module using pycharm, adding the pydev lines inside it works (and official slicer debug extension doesn’t):
import pydevd_pycharm
pydevd_pycharm.settrace('localhost', port=5678, stdoutToServer=True, stderrToServer=True)
Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus