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!
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: FreeCAD api fails in external application

Post by wmayer »

Hmm, this is getting weird. lsof claims that _PartDesign.so is loaded but at the same time it refuses to create a PartDesign::Body.

And this also works?

Code: Select all

import sys
import PartDesign
PartDesign.__file__

sys.modules['_PartDesign']
sys.modules['PartDesign']
drmacro
Veteran
Posts: 8865
Joined: Sun Mar 02, 2014 4:35 pm

Re: FreeCAD api fails in external application

Post by drmacro »

wmayer wrote: Sat Apr 30, 2022 1:15 pm Hmm, this is getting weird. lsof claims that _PartDesign.so is loaded but at the same time it refuses to create a PartDesign::Body.

And this also works?

Code: Select all

import sys
import PartDesign
PartDesign.__file__

sys.modules['_PartDesign']
sys.modules['PartDesign']

Hmm...

import PartDesign fails

Code: Select all

Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
ModuleNotFoundError: No module named 'PartDesign'

Import _PartDesign works

_PartDesign.__file__

Returns:

'/usr/lib/_PartDesign.so'
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
drmacro
Veteran
Posts: 8865
Joined: Sun Mar 02, 2014 4:35 pm

Re: FreeCAD api fails in external application

Post by drmacro »

The following code:

Code: Select all

from collections import defaultdict
import FreeCAD as F
from pprint import pprint

fc_file = r"/home/mac/SharedData/Projects/MechMovements/Simple_assy_001.FCStd"
live_fc = F.open(fc_file)

obj_names = defaultdict(list)
for obj in F.ActiveDocument.Objects:
    ID = str(obj.TypeId)
    A, B = ID.split('::')
    obj_names[A].append(B)

pprint(obj_names)
produces:

Code: Select all

defaultdict(<class 'list'>,
            {'App': ['Origin',
                     'Line',
                     'Line',
                     'Line',
                     'Plane',
                     'Plane',
                     'Plane',
                     'Origin',
                     'Line',
                     'Line',
                     'Line',
                     'Plane',
                     'Plane',
                     'Plane',
                     'Origin',
                     'Line',
                     'Line',
                     'Line',
                     'Plane',
                     'Plane',
                     'Plane'],
I looks like the Origin objects is there...
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: FreeCAD api fails in external application

Post by wmayer »

drmacro wrote: Sat Apr 30, 2022 3:25 pm import PartDesign fails
Import _PartDesign works

_PartDesign.__file__

Returns:

'/usr/lib/_PartDesign.so'
OK, now it starts to make some sense. It could be a packaging bug because the above mentioned __init__.py file is missing.

Where is the PartDesign directory located? You can figure this out by importing PartDesignGui (which I think should work). Then check the path name of its __file__ attribute. Open this directory in a file manager and look for the __init__.py file. If it doesn't exist create it and set its content to:

Code: Select all

import _PartDesign
makeFilletArc = _PartDesign.makeFilletArc
Now try to load the project file with Blender again.
drmacro
Veteran
Posts: 8865
Joined: Sun Mar 02, 2014 4:35 pm

Re: FreeCAD api fails in external application

Post by drmacro »

wmayer wrote: Sat Apr 30, 2022 3:52 pm
drmacro wrote: Sat Apr 30, 2022 3:25 pm import PartDesign fails
Import _PartDesign works

_PartDesign.__file__

Returns:

'/usr/lib/_PartDesign.so'
OK, now it starts to make some sense. It could be a packaging bug because the above mentioned __init__.py file is missing.

Where is the PartDesign directory located? You can figure this out by importing PartDesignGui (which I think should work). Then check the path name of its __file__ attribute. Open this directory in a file manager and look for the __init__.py file. If it doesn't exist create it and set its content to:

Code: Select all

import _PartDesign
makeFilletArc = _PartDesign.makeFilletArc
Now try to load the project file with Blender again.

import PartDesignGui results in "Cannot load Gui module in console application"

find says it is at these places:

Code: Select all

./usr/lib/python3.10/site-packages/PartDesignGui.so
./usr/lib/freecad/Mod/PartDesign/TestPartDesignGui.py
./usr/lib/PartDesignGui.so
In fact there is no PartDesign.so in any of those places, only _PartDesign.so:

Code: Select all

./usr/lib/python3.10/site-packages/_PartDesign.so
./usr/lib/freecad/Mod/PartDesign
./usr/lib/_PartDesign.so
In fact there is no PartDesign.so on the system...

There is a directory: /usr/lib/freecad/Mod/PartDesign/

And it has __init__.py
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
drmacro
Veteran
Posts: 8865
Joined: Sun Mar 02, 2014 4:35 pm

Re: FreeCAD api fails in external application

Post by drmacro »

wmayer wrote: Sat Apr 30, 2022 3:52 pm
My last post was a bit of "streaming thoughts".

I think, I see after comparing to my Debian PC that there isn't supposed to be a PartDesign.so. Is this correct?

In any case, simply adding the __init__.py didn't fix anything and as I noted, there is one already in another directory.

I guess I need to figure out what is the correct conditions before I can talk to the AUR packager.

But, I'm at a bit of a lost as to what I should do or try next...
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
drmacro
Veteran
Posts: 8865
Joined: Sun Mar 02, 2014 4:35 pm

Re: FreeCAD api fails in external application

Post by drmacro »

I have poked around in the directories until I've confused myself.

Is there some place I can look for what would be normal (and correct) as to where things should be after the AUR install has completed?

I'm wondering, if, on this Manjaro PC because I"ve done both a AUR build by hand and through pacman (and during the perios when the AUR build was completely bolloxed because of the jump to Python 3.10) that I have some sort of polluted install situation.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: FreeCAD api fails in external application

Post by onekk »

drmacro wrote: Mon May 02, 2022 12:21 pm I'm wondering, if, on this Manjaro PC because I"ve done both a AUR build by hand and through pacman (and during the perios when the AUR build was completely bolloxed because of the jump to Python 3.10) that I have some sort of polluted install situation.
I have had some problem in the past when a buggy AUR build has left some files around after having compiled the source and during the "put in place" phase.

I don't remind if there is a way to see what AUR has installed if something go wrong. (I'm using an Arch derivative but I'm not an Arch expert), but from what I remember is not like a package where there is a "list of installed files" that could permit to revert the changes.

In fact for complex software I usually prefer the "miniconda" or Appimage or similar install that try to separate the OS from the installed program.

Hope to having not told some insanity.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
drmacro
Veteran
Posts: 8865
Joined: Sun Mar 02, 2014 4:35 pm

Re: FreeCAD api fails in external application

Post by drmacro »

As I noted in the AUR forum freecad-git, I tried the install on a clean Manjaro and it was clear the package did not install correctly and use of the API is broken.

I have seen no further response, here or there, about remedial work.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: FreeCAD api fails in external application

Post by onekk »

drmacro wrote: Wed May 04, 2022 10:20 am As I noted in the AUR forum freecad-git, I tried the install on a clean Manjaro and it was clear the package did not install correctly and use of the API is broken.

I have seen no further response, here or there, about remedial work.
Sadly not everytime the AUR maintainer is responsive, many times you have to manage to solve problem yourself.

Here is somewhat difficult to obtain an answer about and AUR build, the Arch Build System is not too difficult, but it has to cope with the "rolling release" nature of Arch Linux, so maybe some package is "too new" to be "compatible" with the actual "state of the art" on which FC build is based.

This is an old problem well known by users of rolling release distros.

If i didn't go wrong, there are some "scientific distributions" based on Arch Linux that could have some more "up to date" version of FC in their repositories, and studying their PKGBUILD (If there will be any) you maybe will find some solutions.

Sometimes you could make a totally different AUR modifying PKGBUILD to use a "versioned" dependency on problematic libraries, but this is only an old remembering from the past, so I can't tell more detailed informations.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply