create a workbench by C++ and fcbt tool

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!
Post Reply
xc22143
Posts: 139
Joined: Fri Dec 03, 2021 9:52 am

create a workbench by C++ and fcbt tool

Post by xc22143 »

Hello, everyone. I want to create a workbench. I tried to use the fcbt.py tool to create a workbench. After there are myworkbench folder, when I open the FreeCAD and active it, FreeCAD told me that 'No module named 'myworkbenchGui'. I know that it is wrong to do so. I guess that I need to use CMake or compile it? but I don't know what to do. Thank you!
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: create a workbench by C++ and fcbt tool

Post by onekk »

xc22143 wrote: Mon Sep 26, 2022 3:53 am Hello, everyone. I want to create a workbench. I tried to use the fcbt.py tool to create a workbench.
...
From this page, it seems that a C++ WB have to be only the "entry point" in Python, but the rest of the Wb must be coded in C++

https://wiki.freecadweb.org/Workbench_creation

Sadly there are not much information about, but as example if you see:

https://github.com/FreeCAD/FreeCAD/tree ... d/TechDraw

It is mostly If not entirely coded in C++ with only initialisation file and test files in Python.

You have to code the whole Wb or at least a skeleton and compile it to have something to invoke, and myworkbenchGui is clearly only the "fake name" to show an example of class name that has to be created in C++ code.

Sadly there is no more documentation around on how to create C++ WB, so probably you have to wait some more skilled developer to have some answers.

Where you have found fcbt.py file? I have some vague remember of a tool that will create a skeleton for workbenches, but from what I remember it was for Python WB.

Hope it helps.

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/
xc22143
Posts: 139
Joined: Fri Dec 03, 2021 9:52 am

Re: create a workbench by C++ and fcbt tool

Post by xc22143 »

onekk wrote: Mon Sep 26, 2022 6:30 am Where you have found fcbt.py file? I have some vague remember of a tool that will create a skeleton for workbenches, but from what I remember it was for Python WB.
Thank you for your reply! Here are some official introductions for fcbt.https://wiki.freecad.org/FreeCAD_Build_Tool/en
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: create a workbench by C++ and fcbt tool

Post by onekk »

xc22143 wrote: Mon Sep 26, 2022 6:59 am Thank you for your reply! Here are some official introductions for fcbt.https://wiki.freecad.org/FreeCAD_Build_Tool/en
Hello, I' ve seen, but it is simply putting some files in the Mod directory.

It is not clear from the page linked if it create a Python or a C++ file, as I have not tried it, but in both cases, the skeleton should be completed to have even a "do nothing" Module.

Sadly there are not much information about WorkBench creation, you could inspect some code already created, you will find many here:

https://github.com/FreeCAD/FreeCAD-addons

Most of them are Python WB, for C++ WB you have to search and find some not too complicated.

I have not much to say, as C++ is not my best known language and I have only scratched the surface of WB in Python.

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/
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: create a workbench by C++ and fcbt tool

Post by adrianinsaval »

if you don't know how to compile, are you sure you want to do your workbench in C++? I would go with a pure python workbench instead, way easier to write and test.
xc22143
Posts: 139
Joined: Fri Dec 03, 2021 9:52 am

Re: create a workbench by C++ and fcbt tool

Post by xc22143 »

adrianinsaval wrote: Mon Sep 26, 2022 11:52 am if you don't know how to compile, are you sure you want to do your workbench in C++? I would go with a pure python workbench instead, way easier to write and test.
Sorry, I'm not familiar with compiling, but I have to use C++ right now. I successfully compiled FreeCAD according to the compiled wiki documentation, now I created a new workbench by fcbt tool, I don't know if I need to re-build all the source code in Cmake and then recompile all in VS.
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: create a workbench by C++ and fcbt tool

Post by adrianinsaval »

xc22143 wrote: Mon Sep 26, 2022 12:28 pm but I have to use C++ right now.
why? Are you sure? Creating a C++ workbench without even knowing how to compile seems like a pretty big challenge to me. I'm not familiar with the output of fcbt tool but you probably need to add/edit the corresponding cmake files to get your workbench to compile. But let's start with the basics, have you compiled FreeCAD before?
xc22143
Posts: 139
Joined: Fri Dec 03, 2021 9:52 am

Re: create a workbench by C++ and fcbt tool

Post by xc22143 »

adrianinsaval wrote: Mon Sep 26, 2022 12:39 pm
xc22143 wrote: Mon Sep 26, 2022 12:28 pm but I have to use C++ right now.
why? Are you sure? Creating a C++ workbench without even knowing how to compile seems like a pretty big challenge to me. I'm not familiar with the output of fcbt tool but you probably need to add/edit the corresponding cmake files to get your workbench to compile. But let's start with the basics, have you compiled FreeCAD before?
Thank you for your advice. Because my company requires it. I compiled FreeCAD successfully step by step according to the wiki documentation. But I don't understand the principle of compiling behind. It is indeed a pretty big challenge. anyway, thank you very much.
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: create a workbench by C++ and fcbt tool

Post by adrianinsaval »

Then your manager or whoever made that decision is an idiot, they should hire someone with C++ knowledge if they want a C++ workbench or pay for the training if they want an existing employee to do it, otherwise, use python (well they should still hire someone who knows it or train their employee but this should be easier and possibly cheaper).

I don't know a lot of how cmake works either so I suggest you start by reading about it, don't try to learn it along the way if you are working in a serious project (same goes for actual C++), you'd be setting yourself up for trouble. Perhaps create a simple project independent of FreeCAD to start getting accustomed to it.
If you have added your workbench to src/Mod and you want it to get compiled with FreeCAD you need to add it here: https://github.com/FreeCAD/FreeCAD/blob ... eLists.txt and you need a CMakeLists.txt in your addon directory too where you will tell it what files have to be compiled, generated, copied over, etc. See the other C++ workbenches for examples.

Also for future inquiries it might help to know for what platform you are compiling and what version of FreeCAD so you should probably provide that information.
xc22143
Posts: 139
Joined: Fri Dec 03, 2021 9:52 am

Re: create a workbench by C++ and fcbt tool

Post by xc22143 »

adrianinsaval wrote: Mon Sep 26, 2022 1:17 pm
Thank you very much!!! I need to learn more.
Post Reply