Reloading Python code without restarting the FreeCAD
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Reloading Python code without restarting the FreeCAD
Hi guys,
I'm trying to help with a WorkBench development written in Python.
Is there a way to reload python code that belongs to the WB without the need to restart the whole FreeCAD application?
Switching to another WB and back didn't help
Thanks.
I'm trying to help with a WorkBench development written in Python.
Is there a way to reload python code that belongs to the WB without the need to restart the whole FreeCAD application?
Switching to another WB and back didn't help
Thanks.
- microelly2
- Veteran
- Posts: 4688
- Joined: Tue Nov 12, 2013 4:06 pm
- Contact:
Re: Reloading Python code without restarting the FreeCAD
force a reload in the Activatewd method of your command
Code: Select all
Gui.doCommand("import " + modul)
Gui.doCommand("import " + self.lmod)
Gui.doCommand("reload(" + self.lmod + ")")
Gui.doCommand(self.command)
Re: Reloading Python code without restarting the FreeCAD
Thanks, will try.
Re: Reloading Python code without restarting the FreeCAD
Usually doing:
Works just fine. That is when you changed code in SomeModule.py and it was already imported.
Code: Select all
reload(SomeModule.py)
Re: Reloading Python code without restarting the FreeCAD
i remember that is don't work out of the box with py3...triplus wrote: ↑Wed Jul 18, 2018 9:43 am Usually doing:
Works just fine. That is when you changed code in SomeModule.py and it was already imported.Code: Select all
reload(SomeModule.py)
Re: Reloading Python code without restarting the FreeCAD
This works with Python 3:
Code: Select all
reload(MyModule)
Code: Select all
FreeCADGui.addCommand('MyModule', MyModule())
Re: Reloading Python code without restarting the FreeCAD
I use sucessfully:
Code: Select all
import someModule
from importlib import reload
reload(someModule)
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Re: Reloading Python code without restarting the FreeCAD
It would be handy for debugging if there was a button somewhere (or maybe just a "developer" menu item) that would allow you to force FreeCAD to reload a module(s).