[SOLVED] External workbench mixed python/C++

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Gunt
Posts: 14
Joined: Sun Sep 01, 2019 7:31 pm

[SOLVED] External workbench mixed python/C++

Post by Gunt »

Hi,

I have been exploring the possibilities with python-scripting in FreeCad.
I succeeded in making a python test-workbench to play around and learn how it works.
I can make some objects, change objects , change object-colors... All from python-code in this workbench.
Which is great:-) It took me a long time to find out how things work.

To do this, I used info in https://wiki.freecadweb.org/Workbench_creation,
and read existing external-workbench-pythoncode for guidance.
Also read FreeCAD_Mod_Dev_Guide__20190912.pdf

Now I would like to explore making a mixed python/C++ workbench.
I could not find an example of a mixed "external" workbench.
It seems that all existing external-workbenches are made with only python.
And the mixed workbenches are all "Internal" > Installed together with FreeCad.

I downloaded FreeCAD-master.zip from Github, because it contains a folder '_TEMPLATE_'.
I copied this "_TEMPLATE_"-folder to the mod-directory (where the external python-workbenches are stored)
(I read about this "_TEMPLATE_"-folder in FreeCAD_Mod_Dev_Guide__20190912.pdf)

I did not rename the _TEMPLATE_ files.

When I start Freecad, the _TEMPLATE_ workbench shows up in the list of workbenches.
But when I activate it, I get: "No module named '_TEMPLATE_Gui'"
I think that the cpp-files in _TEMPLATE_ are not 'compiled' when freecad starts.

Questions:
In order to make a mixed python/c++ workbench:

1) Do I have to compile Freecad from the source code?
(I installed freecad from https://www.freecadweb.org/downloads.php)

2) Is the "_TEMPLATE_"-folder only for use with Linux?
(I use windows)

3) Does "cmake" play a role in the process of making a mixed python/c++?

Any help would be greatly appreciated!
Kind regards
Gunt

OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.4 (GitTag)
Build type: Release
Branch: releases/FreeCAD-0-18
Hash: 980bf9060e28555fecd9e3462f68ca74007b70f8
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Dutch
Last edited by Gunt on Thu Sep 23, 2021 8:34 pm, edited 1 time in total.
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: External workbench mixed python/C++

Post by wmayer »

I could not find an example of a mixed "external" workbench.
It seems that all existing external-workbenches are made with only python.
And the mixed workbenches are all "Internal" > Installed together with FreeCad.
For the majority of external wbs it's true that they are written in Python because they can be used by only copying over the needed files while for a C++ wb you need a compiler.
I downloaded FreeCAD-master.zip from Github, because it contains a folder '_TEMPLATE_'.
I copied this "_TEMPLATE_"-folder to the mod-directory (where the external python-workbenches are stored)
(I read about this "_TEMPLATE_"-folder in FreeCAD_Mod_Dev_Guide__20190912.pdf)
Under src/Tools you will find the script fcbt.py that you should use instead. It asks you for the name of the new wb and then copies over the file of __TEMPLATE__ to the target location by replacing all occurrences of __TEMPLATE__ with the name you have entered.
Afterwards to must add the directory name to https://github.com/FreeCAD/FreeCAD/blob ... eLists.txt
I think that the cpp-files in _TEMPLATE_ are not 'compiled' when freecad starts.
Of course not. You need a compiler to build the binaries out of the source files.
1) Do I have to compile Freecad from the source code?
Yes.
2) Is the "_TEMPLATE_"-folder only for use with Linux?
No, it's OS-independent. So it works on all OS FreeCAD is running on. (Windows, Linux, macOS and probably FreeBSD).
3) Does "cmake" play a role in the process of making a mixed python/c++?
Yes, you need it to create the project files for your IDE to build the binaries.
Gunt
Posts: 14
Joined: Sun Sep 01, 2019 7:31 pm

Re: External workbench mixed python/C++

Post by Gunt »

The biggest surpise (for me:-) is that I have to compile FreeCAD myself to be able to mix python and C++ in a workbench.

Thanks for the detailed reply!
Gunt
Gunt
Posts: 14
Joined: Sun Sep 01, 2019 7:31 pm

Re: External workbench mixed python/C++

Post by Gunt »

I considere this topic [solved], but I don't know how to annotate is as such...
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: External workbench mixed python/C++

Post by chrisb »

Gunt wrote: Thu Sep 23, 2021 6:59 am I considere this topic [solved], but I don't know how to annotate is as such...
- Edit the first post
- Prepend the text "[Solved]" before the subject. This changes the title of the topic too.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: External workbench mixed python/C++

Post by ickby »

One point that may not yet be clear: when the c++ workbench is compiled it uses the exact same library versions as freecad (that's the reason you compile yourself). Hence it only works with this very special set of libraries, and only on the OS you compiled it. This basically makes your workbench impossible to distribute as standalone package like the python only workbenches, as there are really really many freecad versions out there, with different is, different lib versions etc.

So making a standalone c++ workbench means all users need to compile it themaelf. That's why noone does it.
Gunt
Posts: 14
Joined: Sun Sep 01, 2019 7:31 pm

Re: External workbench mixed python/C++

Post by Gunt »

Thanks ickby for the extra clarification.
I understand that only Python-workbenches are distributable, and probably also easier to use in futures versions of FreeCAD.

Again thanks for all the replies.
And also for the efforts that have been put, and will be put, into Freecad.

From reading other threads in this forum, I understand that it takes loads and loads of energy.
I hope that developers/maintainers find ways to keep the core of FreeCAD maneagable.

I for one am very glad FreeCAD exists, and I believe that open-source, as a phenomenon, will keep growing in the future.


Kind regards,
Gunt
xc22143
Posts: 139
Joined: Fri Dec 03, 2021 9:52 am

Re: [SOLVED] External workbench mixed python/C++

Post by xc22143 »

Hello! I have encountered the same problem. I would like to ask the poster how to operate. Can you elaborate on it?
Post Reply