FreeCAD external Python interpreter will not return body object on Ubuntu 20.04
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Issues with FreeCAD python interface on server
I'd bet for a no, but who knows ???
Re: Issues with FreeCAD python interface on server
My best bet is the python version incompatibility, I will check that later.
FreeCAD als Maschinenbauer in die Konstruktion und Fertigung integrieren. Schulung buchen: www.alsado.de/freecad-schulungen
Re: Issues with FreeCAD python interface on server
Looks like I cannot even get the body object on ubuntu using the python interface with
-> returns none
or
-> returns empty list
Code: Select all
doc.getObject('Body001')
or
Code: Select all
doc.getObjectsByLabel('Body001')
FreeCAD als Maschinenbauer in die Konstruktion und Fertigung integrieren. Schulung buchen: www.alsado.de/freecad-schulungen
Re: Issues with FreeCAD python interface on Ubuntu
Could you just give output of and ?
Code: Select all
doc
Code: Select all
doc.Body001
Re: Issues with FreeCAD python interface on Ubuntu
Code: Select all
doc
Code: Select all
print(doc)
Code: Select all
<Document object at ...>
Code: Select all
doc.Body001
Code: Select all
print(doc.Body001)
Code: Select all
Attrubute error: 'App.Document' object has no attribute 'Body001'
This only happens on ubuntu when using an external interpreter. All of this works fine on ubuntu in the internal interpreter and on Windows using the internal interpreter and an external one.
FreeCAD als Maschinenbauer in die Konstruktion und Fertigung integrieren. Schulung buchen: www.alsado.de/freecad-schulungen
Re: Issues with FreeCAD python interface on Ubuntu
You have to be careful when using an external interpreter. It has to be the exact same version of Python as the one FreeCAD was compiled with.
Re: Issues with FreeCAD python interface on Ubuntu
Thats why my best bet was the interpreter incompatibility but I thought that 3.8.8 (FreeCAD) and 3.8.10 (external) would be compatible. I will give an update once I have installed python 3.8.8 as the external interpreter, but it does not look like its as straight forward as installing the latest stable version.
FreeCAD als Maschinenbauer in die Konstruktion und Fertigung integrieren. Schulung buchen: www.alsado.de/freecad-schulungen
Re: Issues with FreeCAD python interface on Ubuntu
I am still working on installing Python 3.8.8 on Ubuntu 20.04.
I have also tested other FCStd files with very simple bodies, just to be sure, and I also cannot get them using
returns None
I have also tested other FCStd files with very simple bodies, just to be sure, and I also cannot get them using
Code: Select all
doc.getObject("Body")
FreeCAD als Maschinenbauer in die Konstruktion und Fertigung integrieren. Schulung buchen: www.alsado.de/freecad-schulungen
Re: Issues with FreeCAD python interface on Ubuntu
I have installed Python 3.8.8 and it still does not work. FreeCAD just wont return the body object. Can anyone verify this? Operating system is Ubuntu 20.04 with external Python interpreter version 3.8.8. FreeCAD 0.19.2 PPA-stable. This works on Windows 10.
Use this code:
Use this code:
Code: Select all
import sys
# Set working directories
FREECAD_FILES = '/home/aleksander/test-multi-flask-freecad/freecad-files'
# Initialize FreeCAD python interface
sys.path.append('/usr/lib/freecad-python3/lib')
try:
import FreeCAD
except ValueError:
print('FreeCAD library not found. Please check the if the FREECAD_PATH variable is correctly set')
try:
import Part
except:
print('One of the FreeCAD workbenches is missing.')
try:
doc = FreeCAD.openDocument(str(os.path.join(FREECAD_FILES, 'test.FCStd')))
print('FreeCAD file successfully loaded!')
except:
print('FreeCAD file could not be loaded')
body = doc.getObject('Body')
print(body)
#shape = Part.getShape(body, '')
FreeCAD als Maschinenbauer in die Konstruktion und Fertigung integrieren. Schulung buchen: www.alsado.de/freecad-schulungen
Re: Issues with FreeCAD python interface on Ubuntu
I don't really understand why you had to install a specific Python version. The principle of the PPA is to compile FreeCAD against the Python version available in the distro repo...