Starting and controlling FreeCAD from external console

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
JiriVALASEK
Posts: 48
Joined: Wed Apr 17, 2019 7:42 pm

Starting and controlling FreeCAD from external console

Post by JiriVALASEK »

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
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: Starting and controlling FreeCAD from external console

Post by mario52 »

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, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
galou_breizh
Posts: 436
Joined: Wed Sep 15, 2010 9:38 am

Re: Starting and controlling FreeCAD from external console

Post by galou_breizh »

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
Veteran
Posts: 2566
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

Re: Starting and controlling FreeCAD from external console

Post by Jee-Bee »

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

Post by JiriVALASEK »

Thanks for help,

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

Re: Starting and controlling FreeCAD from external console

Post by galou_breizh »

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

Post by JiriVALASEK »

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
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Starting and controlling FreeCAD from external console

Post by microelly2 »

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
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: Starting and controlling FreeCAD from external console

Post by mario52 »

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, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Starting and controlling FreeCAD from external console

Post by Kunda1 »

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)
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Post Reply