Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if "import FreeCAD" already works before starting extraordinary measures #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions cnc25d/importing_freecad.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,32 @@ def importing_freecad():
''' This function looks for the FreeCAD library and import it if needed
just call this function where you want to import FreeCAD
'''
# choose your favorite test to check if you are running with FreeCAD GUI or traditional Python
freecad_gui = True
#if not(FREECADPATH in sys.path): # test based on PYTHONPATH
if not("FreeCAD" in dir()): # test based on loaded module
freecad_gui = False
#print("dbg102: freecad_gui:", freecad_gui)

if not(freecad_gui):
freecad_path=''
for p in FREECADPATH:
if(os.path.isfile("%s/FreeCAD.so"%(p))):
freecad_path=p
if(freecad_path==''):
print("ERR070: Error, the FreeCAD library path has not been found!")
print("Add the path of the directory containing FreeCAD.so to the variable FREECADPATH in the file {:s}".format(__FILE__))
sys.exit(2)
#print("dbg101: add FREECADPATH to sys.path")
sys.path.append(freecad_path)
try:
import FreeCAD
except:
print("ERR080: Error, the FreeCAD library can not be imported by cnc25d!")
try:
import FreeCAD
return
except:
# choose your favorite test to check if you are running with FreeCAD GUI or traditional Python
freecad_gui = True
#if not(FREECADPATH in sys.path): # test based on PYTHONPATH
if not("FreeCAD" in dir()): # test based on loaded module
freecad_gui = False
#print("dbg102: freecad_gui:", freecad_gui)

if not(freecad_gui):
freecad_path=''
for p in FREECADPATH:
if(os.path.isfile("%s/FreeCAD.so"%(p))):
freecad_path=p
if(freecad_path==''):
print("ERR070: Error, the FreeCAD library path has not been found!")
print("Add the path of the directory containing FreeCAD.so to the variable FREECADPATH in the file {:s}".format(__FILE__))
sys.exit(2)
#print("dbg101: add FREECADPATH to sys.path")
sys.path.append(freecad_path)
try:
import FreeCAD
except:
print("ERR080: Error, the FreeCAD library can not be imported by cnc25d!")
sys.exit(2)

################################################################
Expand Down