FreeCAD api fails in external application

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: FreeCAD api fails in external application

Post by Kunda1 »

I would totally try this but my poor poor laptop
Hence ive moved to Snap packages
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
drmacro
Veteran
Posts: 8870
Joined: Sun Mar 02, 2014 4:35 pm

Re: FreeCAD api fails in external application

Post by drmacro »

adrianinsaval wrote: Tue May 17, 2022 11:01 pm @drmacro ok I think I figured it out, here's a working PKGBUILD (remove txt extension), please test that it works without any hacks but please reboot after installation before testing to ensure the PATH_TO_FREECAD_LIBDIR env variable is not set anymore. I'll ask the AUR maintainer to use my PKGBUILD or add me as maintainer to the AUR freecad-git repo

EDIT: I've been added as co-maintainer of the AUR package so I will push my changes tonight once I'm home since I need to setup ssh authentication

EDIT2: done, please test a normal build from AUR again and ping me if something doesn't work (that could be attributed to this build)
@adrianinsaval Sorry it took me so long to get back to this.

As of this posting the latest AUR is actually worse off than before. It can find PartDesign now, but fails to find the _PartDesign called in the __init__.py.

In addition, now the path to the rest of FreeCAD fails (i.e. now it can't find Part.so, FreeCAD.so, etc.)

If I use the following script to launch Blender things do work.

Code: Select all

PYTHONPATH=/usr/lib/freecad/lib:/usr/lib/freecad/Mod
export PYTHONPATH
blender
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: FreeCAD api fails in external application

Post by adrianinsaval »

you need to first import freecad and then everything else will be available, from my understanding that is the intended behavior, you shouldn't need to set PYTHONPATH, what path for freecad do you have configured in sverchok?
How do you run things under debian? current AUR should be more similar to debian behavior

In any case if you are going to use the PYTHONPATH variable you should set it to /usr/lib/freecad/lib
if you check the files from the current package there is no *.so files on /usr/lib they are on /usr/lib/freecad/lib this is more complaint with the filesystem hirearchy standard
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: FreeCAD api fails in external application

Post by adrianinsaval »

Kunda1 wrote: Sun May 29, 2022 1:26 am I would totally try this but my poor poor laptop
Hence ive moved to Snap packages
FYI I'm setting up a personal repo using github actions to compile the package daily, it's not ready to be added as a pacman repo yet but you can find binary packages here: https://github.com/adrianinsaval/pacman ... /archlinux the latest one is smaller than the others because I increased the compression. This way I can get the latest freecad version with just a <60mb download and it gets compiled in less than 15min if I want to trigger it manually.
drmacro
Veteran
Posts: 8870
Joined: Sun Mar 02, 2014 4:35 pm

Re: FreeCAD api fails in external application

Post by drmacro »

adrianinsaval wrote: Sun May 29, 2022 10:50 pm you need to first import freecad and then everything else will be available, from my understanding that is the intended behavior, you shouldn't need to set PYTHONPATH, what path for freecad do you have configured in sverchok?
How do you run things under debian? current AUR should be more similar to debian behavior

In any case if you are going to use the PYTHONPATH variable you should set it to /usr/lib/freecad/lib
if you check the files from the current package there is no *.so files on /usr/lib they are on /usr/lib/freecad/lib this is more complaint with the filesystem hirearchy standard
what path for freecad do you have configured in sverchok?
I have been in discussion in the sverchok github about what actually the sverchok preference setting in Blender actually does. It appears to be a convenience setting that allows FreeCAD to be in place other than standard. So, if Python can find FreeCAD, then it does not need this setting.

This explains why setting it on my main Debian machine (where FreeCAD is not installed) to the build directory I use works. Though I've not seen the same setting work on Manjaro...but, with the PYTHONPATH set as stated no setting is required on Manjaro either.
...if you are going to use...
I don't want to use PYTHONPATH, I want to figure out how a default should work, I mention PYTHONPATH only to note what makes it work.

Hmm...if I remember from my experiments yesterday, without PYTHONPATH set as noted, I couldn't even import freecad...I will double check this shortly.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
drmacro
Veteran
Posts: 8870
Joined: Sun Mar 02, 2014 4:35 pm

Re: FreeCAD api fails in external application

Post by drmacro »

This may be a side note.

But, I just noticed that the sverchok preferences in Blender Set path button attempts to write to :

Code: Select all

usr/lib/python3.10/site-packages
This fails because a normal user does not have write access to /usr/lib...

But, at the Python console (in Blender and in a terminal window) 'import freecad' and then 'import PartDesign' work.

Though 'import freecad' reports:

Code: Select all

>>> import freecad
PATH_TO_FREECAD_LIBDIR not specified, using default FreeCAD version in /usr/lib/freecad/lib
Assembly4 workbench (v0.11.12) loaded
Sheet Metal workbench loaded
That all said, the only condition that allows any freecad nodes from sverchok is with the PYTHONPATH set.
(And, it can no longer find PartDesign. Even though at the Python console import PartDesign does work.)

So, this is back to the original issue of not having access to Body objects in the sverchok nodes. :(
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
drmacro
Veteran
Posts: 8870
Joined: Sun Mar 02, 2014 4:35 pm

Re: FreeCAD api fails in external application

Post by drmacro »

Hmm...still experimenting, but...

Noting from the sverchok node Python:

Code: Select all

from sverchok.dependencies import FreeCAD
Then executing that line on the Blender Python console the FreeCAD module was being read from: '/usr/lib/freecad/lib/FreeCAD.so'

I set that with the sverchok preferences. (I had to give the user access to /usr/lib.)

It now sees PartDesign.

I've done so much tinkering, I need to get back to defaults and re-test to confirm I'm actually seeing the desired result.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
Post Reply