Problem:
I have created this topic to document that I am having issues with the python interpreter on my server. I do not understand what is causing the problem or even what is the problem. The program runs just fine on ubuntu and windows when running it locally. The Python interpreter just says
Code: Select all
shape = Part.getShape(doc.getObject('Body001'), '')
TypeError: argument 1 must be App.DocumentObject, not None
Maybe someone in the future will have the same problem and can comment.
Solution:
The problem was that PartDesign needed to be imported differently and because of that body objects werent recognized. This is not needed on Windows. On Windows, PartDesign can be imported without adding '.../Mod' to path.
Using FreeCAD without a GUI and with an external Python interpreter on Ubuntu (20.04, does probably also apply to other Ubuntu versions).
If I won't forget I will keep this list updated.
1. Use PPA stable FreeCAD distribution
Code: Select all
sudo add-apt-repository ppa:freecad-maintainers/freecad-stable
sudo apt update
sudo apt install freecad freecad-doc
Code: Select all
freecadcmd
[FreeCAD Console mode <Use Ctrl-D (i.e. EOF) to exit.>]
>>> import sys
>>> sys.version
'3.8.10 (default, Jun 2 2021, 10:49:15) \n[GCC 9.4.0]'
Code: Select all
python3
>>> import sys
>>> sys.version
'3.8.10 (default, Jun 2 2021, 10:49:15) \n[GCC 9.4.0]'
Code: Select all
import sys
FREECAD_PATH = 'usr/lib/freecad-python3/lib' #needed for C++ modules or FreeCAD (e.g. 'FreeCAD.ActiveDocument')
FREECAD_MOD_PATH = 'usr/lib/freecad/Mod' #needed for PartDesign and other Python modules
if FREECAD_PATH in sys.path:
pass
else:
sys.path.append(FREECAD_PATH )
if FREECAD_MOD_PATH in sys.path:
pass
else:
sys.path.append(FREECAD_MOD_PATH )
try:
import FreeCAD
except Exception:
print('Cannot import FreeCAD.')
try:
import PartDesign
except Exception:
print('Cannot import PartDesign.')