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: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

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

Post by openBrain »

According https://packages.ubuntu.com/search?keywords=python3 , current version in 20.04 is 3.8.2...
User avatar
Aleks
Posts: 309
Joined: Sun Mar 08, 2020 5:27 pm
Location: Bonn, Germany
Contact:

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

Post by Aleks »

I did not compile FreeCAD. I just downloaded it prebuild. I am using the system installation of python to access FreeCAD through the python interface.
FreeCAD als Maschinenbauer in die Konstruktion und Fertigung integrieren. Schulung buchen: www.alsado.de/freecad-schulungen
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

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

Post by openBrain »

Aleks wrote: Wed Sep 15, 2021 1:17 pm I did not compile FreeCAD. I just downloaded it prebuild. I am using the system installation of python to access FreeCAD through the python interface.
Can you post full FC info from the faulty installation ?
User avatar
Aleks
Posts: 309
Joined: Sun Mar 08, 2020 5:27 pm
Location: Bonn, Germany
Contact:

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

Post by Aleks »

There is no revision number in the info.

Code: Select all

>>> c=App.ConfigDump()
>>> 
>>> c["BuildVersionMinor"]
'19'
>>> c["BuildVersionMajor"]
'0'
>>> c["BuildRevision"]
''
>>> c["BuildRevisionDate"]
'2021/07/21 08:10:00'
>>> c["BuildRevisionBranch"]
'unknown'
>>> c["BuildRevisionHash"]
'0d9536ed3e8c7f40197b5606e1b7873625e1d6fe'
>>> c["BuildRepositoryURL"]
'git://github.com/FreeCAD/FreeCAD.git unknown'
>>> c["OCC_VERSION"] 
Traceback (most recent call last):
  File "<input>", line 1, in <module>
KeyError: 'OCC_VERSION'
FreeCAD als Maschinenbauer in die Konstruktion und Fertigung integrieren. Schulung buchen: www.alsado.de/freecad-schulungen
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

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

Post by openBrain »

Aleks wrote: Wed Sep 15, 2021 1:25 pm There is no revision number in the info.
OK, as you're in headless mode (I guess), let's do it simple.

Can you start

Code: Select all

freecad -c
then enter

Code: Select all

import sys
sys.version
User avatar
Aleks
Posts: 309
Joined: Sun Mar 08, 2020 5:27 pm
Location: Bonn, Germany
Contact:

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

Post by Aleks »

Just to sum up for others so you dont have to read through the whole topic:

On Ubuntu 20.04 and using an to FreeCAD external python interpreter I want to access a body object inside a document through FreeCADs python interface. I am importing FreeCAD in the system python interpreter. But freecad wont return the body object. Can anyone reproduce this? Maybe you know what the problem is.

To reproduce it use this testfile with two simple objects, one body (PartDesign workbench) and one Extrude feature (Part workbench) and the code below.
You can also create your own testfile with a body object.
test.FCStd
(11.05 KiB) Downloaded 51 times
Returning the extrude object works, while returning the body does not work.

Code: Select all

import sys

# Set test file directory
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')
extrude = doc.getObject('Extrude')
print(body)
print(extrude)

My freecad python interpreter

Code: Select all

freecad -c
[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]'
And this is the system interpreter

Code: Select all

python3
>>> import sys
>>> sys.version
'3.8.10 (default, Jun  2 2021, 10:49:15) \n[GCC 9.4.0]'
Last edited by Aleks on Fri Sep 24, 2021 10:29 am, edited 7 times in total.
FreeCAD als Maschinenbauer in die Konstruktion und Fertigung integrieren. Schulung buchen: www.alsado.de/freecad-schulungen
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

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

Post by openBrain »

:? Unfortunately I no more have a computer with 20.04 installed. Hopefully one may test it and report.
jbi
Posts: 117
Joined: Sun Apr 24, 2016 3:28 pm

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

Post by jbi »

Hi,
I had issues with the file permissions on my server. Have you checked this?
User avatar
Aleks
Posts: 309
Joined: Sun Mar 08, 2020 5:27 pm
Location: Bonn, Germany
Contact:

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

Post by Aleks »

Permissions of what file? The problem also exist when trying to return a body from an external interpreter locally.
Returning other objects from the document works. Just returning bodies does not work, which is a problem.
FreeCAD als Maschinenbauer in die Konstruktion und Fertigung integrieren. Schulung buchen: www.alsado.de/freecad-schulungen
jbi
Posts: 117
Joined: Sun Apr 24, 2016 3:28 pm

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

Post by jbi »

Files which i uploaded with the webapp, and which i tried to access with the external python interpreter. I am using also a virtual environment for the webapp, and process the data with an external daemon which uses the freecad libaries. The solution in my case was add the daemon user to the webapp user.
Post Reply