Starting and controlling FreeCAD from external console

Need help, or want to share a macro? Post here!
JiriVALASEK
Posts: 48
Joined: Wed Apr 17, 2019 7:42 pm

Starting and controlling FreeCAD from external console

Postby JiriVALASEK » Wed Apr 17, 2019 7:54 pm

Hi,

Does anyone know, if there is a way how to start FreeCAD with GUI, open a workbench, run some commands/MACRO from a python console or for example MATLAB?

I'd like to do some visualizations in FreeCAD based on computations from MATLAB/python/Julia script. The ideal would be to be able to control the GUI online from outside, but being able to start FreeCAD GUI, open a file and run a MACRO would be sufficient.

Thanks
mario52
Posts: 2695
Joined: Wed May 16, 2012 2:13 pm

Re: Starting and controlling FreeCAD from external console

Postby mario52 » Sat Apr 20, 2019 10:13 am

hi

maybe Embedding_FreeCAD for include FreeCAD ...

here command Python for execute FreeCAD

Code: Select all

import os  # executer un programme externe
os.startfile("C:/Program Files/FreeCAD 0.17/bin/FreeCAD.exe") 
here for execute FreeCAD and the macro if the .FCMacro is associate to FreeCAD

Code: Select all

import os  # executer un programme externe
os.startfile("C:/Users/Your_User_name/AppData/Roaming/FreeCAD/Macro/Macro_Window_fonts_Single.FCMacro")
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
galou_breizh
Posts: 259
Joined: Wed Sep 15, 2010 9:38 am

Re: Starting and controlling FreeCAD from external console

Postby galou_breizh » Sun Apr 21, 2019 8:42 am

Ahoj,

you can either directly start FreeCAD (with GUI), IIRC with `FreeCAD macro_name.FCMacro` and use the full featured embedded Python console or use the FreeCAD kernel for Jupyter (https://github.com/looooo/jupyter_freecad_kernel) for a more pleasant interaction with Python.

For Matlab it can be more difficult but not impossible because some people already managed to interact with FreeCAD from Javascript though some server running within FreeCAD. I don't know anything ready for Matlab.

Cheers,
Gaël
Jee-Bee
Posts: 1972
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

Re: Starting and controlling FreeCAD from external console

Postby Jee-Bee » Mon Apr 22, 2019 8:05 am

numpy and matplotlib (both are python packages for numerical computing) should working with FreeCAD

Matplotlib isn't added by default i think. but some workbenches use it so it should be possible.

https://www.numpy.org
https://matplotlib.org
JiriVALASEK
Posts: 48
Joined: Wed Apr 17, 2019 7:42 pm

Re: Starting and controlling FreeCAD from external console

Postby JiriVALASEK » Mon Apr 22, 2019 9:41 am

Thanks for help,

I found a way to do what I need using a custom workbench and a server.
galou_breizh
Posts: 259
Joined: Wed Sep 15, 2010 9:38 am

Re: Starting and controlling FreeCAD from external console

Postby galou_breizh » Mon Apr 29, 2019 7:08 pm

Nice! Glad you solved your problem. If your workbench is something general, could you consider sharing it and documenting its use?

Thanks,
Gaël
JiriVALASEK
Posts: 48
Joined: Wed Apr 17, 2019 7:42 pm

Re: Starting and controlling FreeCAD from external console

Postby JiriVALASEK » Thu Oct 10, 2019 6:53 am

galou_breizh wrote:
Mon Apr 29, 2019 7:08 pm
Nice! Glad you solved your problem. If your workbench is something general, could you consider sharing it and documenting its use?

Thanks,
Gaël
Hi, I just finished it - https://github.com/JiriValasek/Animate - this is it. The server tool does exactly what I wanted.
User avatar
microelly2
Posts: 4455
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Starting and controlling FreeCAD from external console

Postby microelly2 » Thu Oct 10, 2019 7:15 am

JiriVALASEK wrote:
Thu Oct 10, 2019 6:53 am
Hi, I just finished it - https://github.com/JiriValasek/Animate - this is it. The server tool does exactly what I wanted.
Thank you for sharing this.
mario52
Posts: 2695
Joined: Wed May 16, 2012 2:13 pm

Re: Starting and controlling FreeCAD from external console

Postby mario52 » Thu Oct 10, 2019 9:41 am

hi

good macro thank for sharing

for install it with AddonManager you must replace

Code: Select all

FreeCAD.getHomePath()
by

Code: Select all

FreeCAD.getUserAppDataDir()
in this mode your addon is usable directly with many instalation of FreeCAD ( os Windows)
(what I have done)

thanks

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
User avatar
Kunda1
Posts: 5949
Joined: Thu Jan 05, 2017 9:03 pm

Re: Starting and controlling FreeCAD from external console

Postby Kunda1 » Thu Oct 10, 2019 1:17 pm

sort of related, but more as a joke: If you're really interested in controlling FreeCAD externally:
https://forum.freecadweb.org/viewtopic.php?f=24&t=29988& (FrontPanel Simulation WB)
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features