FreeCAD external Python interpreter will not return body object on Ubuntu 20.04

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Issues with FreeCAD python interface on server

Post by openBrain »

I'd bet for a no, but who knows ???
User avatar
Aleks
Posts: 309
Joined: Sun Mar 08, 2020 5:27 pm
Location: Bonn, Germany
Contact:

Re: Issues with FreeCAD python interface on server

Post by Aleks »

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
User avatar
Aleks
Posts: 309
Joined: Sun Mar 08, 2020 5:27 pm
Location: Bonn, Germany
Contact:

Re: Issues with FreeCAD python interface on server

Post by Aleks »

Looks like I cannot even get the body object on ubuntu using the python interface with

Code: Select all

doc.getObject('Body001')
-> returns none

or

Code: Select all

doc.getObjectsByLabel('Body001')
-> returns empty list
FreeCAD als Maschinenbauer in die Konstruktion und Fertigung integrieren. Schulung buchen: www.alsado.de/freecad-schulungen
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Issues with FreeCAD python interface on Ubuntu

Post by openBrain »

Could you just give output of

Code: Select all

doc
and

Code: Select all

doc.Body001
?
User avatar
Aleks
Posts: 309
Joined: Sun Mar 08, 2020 5:27 pm
Location: Bonn, Germany
Contact:

Re: Issues with FreeCAD python interface on Ubuntu

Post by Aleks »

Code: Select all

doc
does not return anything



Code: Select all

print(doc)
returns

Code: Select all

<Document object at ...>


Code: Select all

doc.Body001
and

Code: Select all

print(doc.Body001)
both return

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
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Issues with FreeCAD python interface on Ubuntu

Post by openBrain »

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.
User avatar
Aleks
Posts: 309
Joined: Sun Mar 08, 2020 5:27 pm
Location: Bonn, Germany
Contact:

Re: Issues with FreeCAD python interface on Ubuntu

Post by Aleks »

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
User avatar
Aleks
Posts: 309
Joined: Sun Mar 08, 2020 5:27 pm
Location: Bonn, Germany
Contact:

Re: Issues with FreeCAD python interface on Ubuntu

Post by Aleks »

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

Code: Select all

doc.getObject("Body")
returns None
FreeCAD als Maschinenbauer in die Konstruktion und Fertigung integrieren. Schulung buchen: www.alsado.de/freecad-schulungen
User avatar
Aleks
Posts: 309
Joined: Sun Mar 08, 2020 5:27 pm
Location: Bonn, Germany
Contact:

Re: Issues with FreeCAD python interface on Ubuntu

Post by Aleks »

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:

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
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Issues with FreeCAD python interface on Ubuntu

Post by openBrain »

Aleks wrote: Wed Sep 15, 2021 12:29 pm 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.
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... :?
Post Reply