Python bindings for Surface WB

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Chris_G
Veteran
Posts: 2596
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Python bindings for Surface WB

Post by Chris_G »

Hi,
I would like to give a try at adding python bindings to Surface workbench.
Some people sometimes want to access the surface tools from python.
And it would add flexibility, making it a hybrid C++ / python workbench.

After a little web search, I saw that there are several solutions available.
The one that seems to be already used in FreeCAD are :
- pybind11
- boost.python
- PyCXX (not sure about this one, but I think I saw this name several times ???)
- custom FreeCAD bindings, like in the Part module, and looking much like this.

I am used to the Part module solution, but it is quite a lot of code writing.
So, I would like to have advise from skilled developers.

Thanks in advance.
User avatar
Gift
Posts: 769
Joined: Tue Aug 18, 2015 10:08 am
Location: Germany, Sauerland

Re: Python bindings for Surface WB

Post by Gift »

Hello Chris,

it is possible the use pythonocc-core now with conda. [1]

[1] https://forum.freecadweb.org/viewtopic. ... 62#p425495

kind regards
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Python bindings for Surface WB

Post by openBrain »

User avatar
Chris_G
Veteran
Posts: 2596
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Python bindings for Surface WB

Post by Chris_G »

Gift wrote: Sat Sep 19, 2020 3:26 pm it is possible the use pythonocc-core now with conda. [1]
Thanks,
This look like a good OCC testing / exploring solution, but not really suited for python bindings inside FreeCAD master.
And I have not been able to build it from AUR on Manjaro Linux :oops:
openBrain wrote: Sat Sep 19, 2020 3:54 pm Maybe this can be of help: https://forum.freecadweb.org/viewtopic.php?f=10&t=43316
Thanks, maybe this will be of help, if the same python binding generator is chosen.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Python bindings for Surface WB

Post by vocx »

Chris_G wrote: Sat Sep 19, 2020 2:15 pm ...
- custom FreeCAD bindings, like in the Part module, and looking much like this.
...
I found this historical thread, How these things work together.

Unfortunately, it's unclear if the situation has changed a lot in 10 years or not. It seems to me that manual wrapping is still the norm, and I don't quite see where PyCXX and pybind11 are used. I think pybind11 is used at least in the Mesh Workbench with a couple of commands, surface flattening, (boost-python deprecated?).

This is the most recent thread I can think about, [How to ?] Expose C++ functions to FreeCAD Python API.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
Chris_G
Veteran
Posts: 2596
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Python bindings for Surface WB

Post by Chris_G »

vocx wrote: Sat Sep 19, 2020 4:21 pm I found this historical thread, How these things work together.
Interesting reading.
vocx wrote: Sat Sep 19, 2020 4:21 pm Unfortunately, it's unclear if the situation has changed a lot in 10 years or not.
That's why I wanted to dip a toe in the water, first ;)
Cyril
Posts: 133
Joined: Wed Aug 23, 2017 5:04 pm
Location: Geneva (Switzerland)
Contact:

Re: Python bindings for Surface WB

Post by Cyril »

pybind11 is relatively easy and apparently very good. python-occ-core and ifcopenshell use swig which looks awful. Also there is one like more like pybind made by Qt guys. See Cristián Maureira-Fredes - Unleash the power of C++ in Python and Talk: Dr. Cristián Maureira-Fredes - C++ ♥ Python: from modules to hybrid applications there also some talks specific about pybind.
I blog about HVAC / BIM / Energy : pythoncvc.net. If you like you can follow the RSS feed.
User avatar
vanuan
Posts: 539
Joined: Wed Oct 24, 2018 9:49 pm

Re: Python bindings for Surface WB

Post by vanuan »

Chris_G wrote: Sat Sep 19, 2020 4:17 pm And I have not been able to build it from AUR on Manjaro Linux
The most reliable way to build it is to use Docker: https://wiki.freecadweb.org/Compile_on_Docker
It takes some time to get used to but after you learn it you would forget you ever had any issues with development dependencies.
User avatar
Chris_G
Veteran
Posts: 2596
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Python bindings for Surface WB

Post by Chris_G »

Cyril wrote: Sat Sep 19, 2020 8:42 pm pybind11 is relatively easy and apparently very good.
It seems to be a good candidate, along with FreeCAD custom one.
vanuan wrote: Sun Sep 20, 2020 2:37 am The most reliable way to build it is to use Docker: https://wiki.freecadweb.org/Compile_on_Docker
I was talking about pythonocc. FreeCAD builds flawlessly.
Cyril
Posts: 133
Joined: Wed Aug 23, 2017 5:04 pm
Location: Geneva (Switzerland)
Contact:

Re: Python bindings for Surface WB

Post by Cyril »

Chris_G wrote: Sun Sep 20, 2020 7:26 amI was talking about pythonocc. FreeCAD builds flawlessly.
See this issue : https://github.com/tpaviot/pythonocc-co ... -683884628 I personally just rolled back to OCC previous version.
Also, you don't need to build python-occ-core from AUR, it is in community packages : https://www.archlinux.org/packages/comm ... -occ-core/
I blog about HVAC / BIM / Energy : pythoncvc.net. If you like you can follow the RSS feed.
Post Reply