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
[SOLVED] External workbench mixed python/C++
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
[SOLVED] External workbench mixed python/C++
Last edited by Gunt on Thu Sep 23, 2021 8:34 pm, edited 1 time in total.
Re: External workbench mixed python/C++
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 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.
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.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)
Afterwards to must add the directory name to https://github.com/FreeCAD/FreeCAD/blob ... eLists.txt
Of course not. You need a compiler to build the binaries out of the source files.I think that the cpp-files in _TEMPLATE_ are not 'compiled' when freecad starts.
Yes.1) Do I have to compile Freecad from the source code?
No, it's OS-independent. So it works on all OS FreeCAD is running on. (Windows, Linux, macOS and probably FreeBSD).2) Is the "_TEMPLATE_"-folder only for use with Linux?
Yes, you need it to create the project files for your IDE to build the binaries.3) Does "cmake" play a role in the process of making a mixed python/c++?
Re: External workbench mixed python/C++
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
Thanks for the detailed reply!
Gunt
Re: External workbench mixed python/C++
I considere this topic [solved], but I don't know how to annotate is as such...
Re: External workbench mixed python/C++
- 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.
Re: External workbench mixed python/C++
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.
So making a standalone c++ workbench means all users need to compile it themaelf. That's why noone does it.
Re: External workbench mixed python/C++
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
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
Re: [SOLVED] External workbench mixed python/C++
Hello! I have encountered the same problem. I would like to ask the poster how to operate. Can you elaborate on it?