Changing the import file doesn't get effect until restart FreeCAD

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
stefankorisnik3
Posts: 101
Joined: Sun Jul 24, 2022 12:49 pm

Changing the import file doesn't get effect until restart FreeCAD

Post by stefankorisnik3 »

I have main file and the other file that i'm including in the main file.
I have forgotten to

Code: Select all

import Part
in the other file and get the error.
Now i fix it by adding this line in the other file but error still persist.
After restarting the FreeCAD application error is gone.
Do i need every time to restart the FreeCAD application when i need to import something in the other file?

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.29177 (Git)
Build type: Release
Branch: releases/FreeCAD-0-20
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.2
Locale: English/United Kingdom (en_GB)
Installed mods: 
  * CurvedShapes 1.0.3
  * Curves 0.5.2
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Changing the import file doesn't get effect until restart FreeCAD

Post by onekk »

stefankorisnik3 wrote: Thu Aug 04, 2022 1:38 pm I have main file and the other file that i'm including in the main file.
I have forgotten to

Code: Select all

import Part
in the other file and get the error.
Now i fix it by adding this line in the other file but error still persist.
After restarting the FreeCAD application error is gone.
Do i need every time to restart the FreeCAD application when i need to import something in the other file?

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.29177 (Git)
Build type: Release
Branch: releases/FreeCAD-0-20
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.2
Locale: English/United Kingdom (en_GB)
Installed mods: 
  * CurvedShapes 1.0.3
  * Curves 0.5.2
Importing from "nested" source files, are subject to some caching mechanism, that could be on some excerpts circumvented using importlib.reload in the main file, but this use has some drawbacks.

Sadly this could not be done everytime and not as example if you program a WB, the import mechanism is derived from Python and this is a:

- known problem
- with some partial solutions
- out of control of FC developers in many aspects.

I've not found a general solution for complex and nested sources the only reliable way is to restart FreeCAD, especially when you are having erratic results.

This will avoid a lot of headaches.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
jbi
Posts: 117
Joined: Sun Apr 24, 2016 3:28 pm

Re: Changing the import file doesn't get effect until restart FreeCAD

Post by jbi »

Code: Select all

import importlib
importlib.reload(otherfile)
of course you could wrap that in a try / except block
Post Reply