[Solved] name 'FreeCADGui' is not defined in InitGui.py

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
phixxx5
Posts: 10
Joined: Tue Jul 27, 2021 1:36 pm

[Solved] name 'FreeCADGui' is not defined in InitGui.py

Post by phixxx5 »

When starting FreeCAD my workbench fails to load and I get the error message:

Code: Select all

During initialization the error name 'FreeCADGui' is not defined occurred in /home/philip/.FreeCAD/Mod/OSM-Buildings/InitGui.py
InitGui.py starts with the following:

Code: Select all

import FreeCAD, FreeCADGui
...
Is something wrong with my python installation? I am on Ubuntu 20.04. I have Anaconda installed but I think FreeCAD uses the standard system python version not the conda environment.
Last edited by phixxx5 on Fri Feb 25, 2022 10:15 am, edited 1 time in total.
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: name 'FreeCADGui' is not defined in InitGui.py

Post by TheMarkster »

Other addon workbenches in that folder work? Unknown? Install one and find out.

Here is how I start InitGui.py for DynamicData workbench:

Code: Select all

import dynamicdatawb_locator
dynamicdataWBPath = os.path.dirname(dynamicdatawb_locator.__file__)
dynamicdataWB_icons_path = os.path.join(dynamicdataWBPath,'Resources','icons')

global main_dynamicdataWB_Icon

main_dynamicdataWB_Icon = os.path.join(dynamicdataWB_icons_path , 'DynamicDataLogo.svg')
There is an empty file named dynamicdatawb_locator.py in the same folder.
phixxx5
Posts: 10
Joined: Tue Jul 27, 2021 1:36 pm

Re: name 'FreeCADGui' is not defined in InitGui.py

Post by phixxx5 »

I solved the problem by removing the import statements for FreeCAD and FreeCADGui
KAKM
Posts: 112
Joined: Tue May 04, 2021 12:17 am

Re: name 'FreeCADGui' is not defined in InitGui.py

Post by KAKM »

That's a problem I have periodically, and it's usually because I used

Code: Select all

import FreeCADGui as Gui
which means that any place you would normally use FreeCADGui to access something, you need to use Gui instead. For example, instead of using

Code: Select all

FreeCADGui.Selection.getSelection()
, you would use

Code: Select all

Gui.Selection.getSelection()
It happens because you essentially rename the module as you import it so that accessing its methods can be done with shorter lines of code.
Post Reply