Cannot load GUI module in console application

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
misterwazlib
Posts: 39
Joined: Mon Dec 04, 2017 10:05 pm

Cannot load GUI module in console application

Post by misterwazlib »

Hello,

I'm quite new to programming in general but I'm currently trying to do the FEM simulation in FreeCAD directly from the command line without using the GUI and I'm having some difficulties.

When I ran my preliminary python script from the command line, I keep getting error messages that the GUI module can't be loaded. Is it at all possible to load the GUI modules without using the GUI?

Secondly, when I tried to record macros for some of the commands in the FEM workbench, the python scripts came out incomplete (for example to create FEM material for solid & to mesh) or didn't come out at all (to run calculix). Is there another way to automate these commands using a python script?

Thanks before!
Attachments
test_freecad.py
(4.1 KiB) Downloaded 147 times
Macro_Recording_Create_Material_Solid.PNG
Macro_Recording_Create_Material_Solid.PNG (6.96 KiB) Viewed 3960 times
Error_Message_Cmd.PNG
Error_Message_Cmd.PNG (7.61 KiB) Viewed 3960 times
Jee-Bee
Veteran
Posts: 2566
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

Re: Cannot load GUI module in console application

Post by Jee-Bee »

First i would advise look at the FEM scripting tutorial: https://www.freecadweb.org/wiki/FEM_Tutorial_Python
ansecond as i read you're error message you can't use gui tools for commandline. but i don't know if that is complete possible i don't do that without gui...
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Cannot load GUI module in console application

Post by bernd »

The FEM Python tutorial was mentioned before. Try this. It should answer most of your questions.

as far as I remember ccx tools solver can not run without gui, but the new solver frame work solver can.

My hint. Run your Python code in GUI mode. Anything in FEM should be possible (apart from netgen mesh, this is cumbersome). If it works run the code in non gui.
misterwazlib
Posts: 39
Joined: Mon Dec 04, 2017 10:05 pm

Re: Cannot load GUI module in console application

Post by misterwazlib »

Hello,

is it possible to generate .inp file for Calculix without Gui? I found FemInputWriterCcx.py but I'm not sure how to use it.

I'm still trying to find a way around using Calculix as solver for FreeCAD without having to open the Gui. Because as far as I know, the other solver can't solve transient state, or am I mistaken?
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Cannot load GUI module in console application

Post by bernd »

what is your FreeCAD version?
misterwazlib
Posts: 39
Joined: Mon Dec 04, 2017 10:05 pm

Re: Cannot load GUI module in console application

Post by misterwazlib »

Hi Bernd,

it's 0.17 version
Attachments
Freecad_Version.PNG
Freecad_Version.PNG (6.97 KiB) Viewed 3789 times
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Cannot load GUI module in console application

Post by Kunda1 »

misterwazlib wrote: Fri Jan 05, 2018 6:50 pm
Since server space costs $ please use the Help > About FreeCAD > Copy to clipboard feature and just paste the info next time. Thanks
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
misterwazlib
Posts: 39
Joined: Mon Dec 04, 2017 10:05 pm

Re: Cannot load GUI module in console application

Post by misterwazlib »

Kunda1 wrote: Fri Jan 05, 2018 8:14 pm Since server space costs $ please use the Help > About FreeCAD > Copy to clipboard feature and just paste the info next time. Thanks
ah okay sorry, I'll do that next time ;)
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Cannot load GUI module in console application

Post by bernd »

misterwazlib wrote: Thu Jan 04, 2018 8:55 pm is it possible to generate .inp file for Calculix without Gui? I found FemInputWriterCcx.py but I'm not sure how to use it.

I'm still trying to find a way around using Calculix as solver for FreeCAD without having to open the Gui. Because as far as I know, the other solver can't solve transient state, or am I mistaken?
to generate a inp file by Python you should follow the tutorial FEM_Tutorial_Python You should try this with FreeCAD Gui. If it works for you, than you should try this without gui.

cheers bernd
misterwazlib
Posts: 39
Joined: Mon Dec 04, 2017 10:05 pm

Re: Cannot load GUI module in console application

Post by misterwazlib »

Hi Bernd thanks for the reply,
bernd wrote: Thu Jan 11, 2018 1:31 pm to generate a inp file by Python you should follow the tutorial FEM_Tutorial_Python
the code in the tutorial to run the analysis works perfectly within the Gui, unfortunately when run on my cmd prompt I received import error for modules like FemGui and FemToolsCcx (no module named FreeCAD). Is there a way to overcome this that you know of?

Is it also possible to export only the .inp file that is generated by the code? As shown in my screenshot it seems that the inp file is stored within the ccx.exe but I couldn't get my hands on it.

Many thanks!
Attachments
ccx_result.PNG
ccx_result.PNG (21.19 KiB) Viewed 3682 times
Post Reply