Controlling FreeCAD from external app in C++ / C# -possible?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
TT-RS
Posts: 70
Joined: Fri Oct 24, 2014 9:19 pm

Controlling FreeCAD from external app in C++ / C# -possible?

Post by TT-RS »

Hello everybody!!

I want to make application that will control (drive) FreeCAD. I know about API, and that there is possibility with Python macros (a lot of them are here on forum and wiki). I am asking if it is possible to drive FreeCAD from my "external" application (in C++ or C#)??
I want to make something like add-ons (you know them if you use commercial CADs). I am thinking about making something like GearTrax, GearTeq, GWJ eAssistant, etc. (with slightly different functionality).

I am interested to run FreeCAD, make geometry (FreeCAD will do it), save files and close FreeCAD.

Hope you can give me some directions!

If it is not possible with external app in C++/C#, please tell me at least how to make add-in in Python fully integrated with FreeCAD (I mean, I would like to have my button, menu items, and panels in FreeCAD). I mean I want to extend Part Design Workbench with my function(s) and give user GUI consistent with this in FreeCAD (Especially I am thinking about panel with options to configure my function/operation, etc.).

Regards.
TT-RS

PS. Hope you understand my "English" ;)
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Controlling FreeCAD from external app in C++ / C# -possi

Post by DeepSOIC »

I'm not sure, but take a look at console mode of freecad. AFAIK it is possible to launch FreeCAD without GUI and feed python commands via stdin/whatever.
User avatar
TT-RS
Posts: 70
Joined: Fri Oct 24, 2014 9:19 pm

Re: Controlling FreeCAD from external app in C++ / C# -possi

Post by TT-RS »

DeepSOIC wrote:I'm not sure, but take a look at console mode of freecad. AFAIK it is possible to launch FreeCAD without GUI and feed python commands via stdin/whatever.
I think this is also good solution for me, if you or someone else know something more about it (how to so it) please share information....

The second solution (by mario52) using Python is OK, but in this case I would like to use different programming lamnguage.
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: Controlling FreeCAD from external app in C++ / C# -possi

Post by ickby »

Another programing language for the command line version is not possible, freecad is tightly integrated with python, anything else won't work.
In general controlling annother program from c++ is possible as subprocess, but this basically only spawns the other app and gives minimal interaction possibility. Integrating two applications is in general not possible as both have seperate event queues etc...

It is not exactly clear what you want to do, but I think you should be really careful with the decision:

1. FreeCAD in console mode with python allows you to use the full freecad power in modeling terms, however, you won't have any gui. This means no 3d viewer etc...
2. FreeCAD Gui embedded in python program gives you all the modeling and the gui which can be controlled from you python program, but this is imho a bit cumbersome
3. If your c++ program uses QT for gui you can embed freecad widgets into your application easily. But FreecAD is a whole eco-system with workbenches,commands etc. and therefore it is not that simple to seperate stuff. And if you integrate the whole main window then you have the same as normal freecad.
4. Create a own freecad workbench with the stuff you like to do. Easy, can be done in c++ or python (or both together) and gives acceess to everything.

If you like to make addons then a custom workbench (the freecad equivalent of an addon) is imho the simpelst thing. But of course I don't know your requirements,
User avatar
TT-RS
Posts: 70
Joined: Fri Oct 24, 2014 9:19 pm

Re: Controlling FreeCAD from external app in C++ / C# -possi

Post by TT-RS »

Thanks for reply, I asked because I wanted to make one appplication for few CAD systems (Windows based only). Now I see it is rather hard and I decided to make two apps (Cross-platform one for FreeCAD + Windows based for the rest of CAD systems).
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Controlling FreeCAD from external app in C++ / C# -possi

Post by jmaustpc »

TT-RS wrote:Thanks for reply, I asked because I wanted to make one appplication for few CAD systems (Windows based only). Now I see it is rather hard and I decided to make two apps (Cross-platform one for FreeCAD + Windows based for the rest of CAD systems).
I don't understand what you mean by that, could you provide more information?
User avatar
TT-RS
Posts: 70
Joined: Fri Oct 24, 2014 9:19 pm

Re: Controlling FreeCAD from external app in C++ / C# -possi

Post by TT-RS »

@jmaustpc - I meant I wanted to make one app in C++ or C# for Windows environment for few CAD packages (not only FreeCAD, but also SW, SE and maybe also Inventor).
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Controlling FreeCAD from external app in C++ / C# -possi

Post by jmaustpc »

TT-RS wrote:@jmaustpc - I meant I wanted to make one app in C++ or C# for Windows environment for few CAD packages (not only FreeCAD, but also SW, SE and maybe also Inventor).
Are you saying that you want to make one application that embeds FreeCAD, SW etc... as in effect some sort of plug ins to your application. So you would start your application and then have it run FreeCAD, SW etc...

Or are you saying that you want to make an application that is some sort of a plug-in that can be plugged into FreeCAD or SW etc.... In which case a user would start FreeCAD or SW etc. and then use FreeCAD SW etc... to start your application.
User avatar
TT-RS
Posts: 70
Joined: Fri Oct 24, 2014 9:19 pm

Re: Controlling FreeCAD from external app in C++ / C# -possi

Post by TT-RS »

Ofcourse that would be several applications (one for each CAD system, but - firstly I wanted them to develop - all in one language and for one platform (Windows)), I hoped to have re-use most of code ("engine" + same GUI) in them. I have already made simple app ("Hello world" kind :) ) that works fine for SW & SE.

I plan to make something like GearTrax / GearTeq / eAssistant but with different objects to generate (less gears, more other stuff).
Post Reply