File reload?

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
chrisb
Veteran
Posts: 54201
Joined: Tue Mar 17, 2015 9:14 am

File reload?

Post by chrisb »

I have asked a similar question already in the Path/CAM forum, but since it seems to be a more general question I dare to ask again here:
I want to write my own post processor which usually is some try and error - and corrections of the errors. The problem is, that I have to restart FreeCAD everytime I want to test a new version.
I have already tried the following:
  • reload the path module with reload(Path)
  • execfile(postprocessorFile)
  • execute the complete code in the python console
Neither the constants defined in the beginning of the file nor the change in the functions change. I think it might be something very simple that I am missing.
BTW: In the meantime the post processor works already pretty well, although not perfect.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: File reload?

Post by ulrich1a »

I do not fully understand, in which file do you made changes, that are not visible after the change?
Is it the path module, or is it in your postprocessor?
When it is in your postprocessor, that gets imported somewhere, you may need to do: reload(postprocessor)

I had a case where I wanted to call functions in a macro from a second file, in order to test specific functionality.
I put two lines in the second file:

Code: Select all

import macro
reload(macro)
With this approach, I could make changes in the macro and got the changed behavior just after the change. Otherwise, I had the same effect, that I had to restart FreeCAD, in order to see the changes in the macro with my second file.

Ulrich
chrisb
Veteran
Posts: 54201
Joined: Tue Mar 17, 2015 9:14 am

Re: File reload?

Post by chrisb »

Success! Thank you, works like expected.
To clarify things: The postprocessor code is in the file maho_post.py. The filename is entered with it's path in the path workbench.
To reload I have to use it as a module name, i.e. without path, without quotes, without extension .py.

Code: Select all

import maho_post
reload(maho_post)
Chris
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
danreb
Posts: 57
Joined: Wed Mar 14, 2018 7:27 pm

Re: File reload?

Post by danreb »

in python >=3.4

e.g. for Arch module

Code: Select all

# in the python console of freecad
import importlib
import Arch
importlib.reload(Arch)
Post Reply