Cannot load GUI module in console application

Need help, or want to share a macro? Post here!
misterwazlib
Posts: 39
Joined: Mon Dec 04, 2017 10:05 pm

Cannot load GUI module in console application

Postby misterwazlib » Tue Dec 12, 2017 10:04 pm

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 60 times
Macro_Recording_Create_Material_Solid.PNG
Macro_Recording_Create_Material_Solid.PNG (6.96 KiB) Viewed 1285 times
Error_Message_Cmd.PNG
Error_Message_Cmd.PNG (7.61 KiB) Viewed 1285 times
Jee-Bee
Posts: 1950
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

Re: Cannot load GUI module in console application

Postby Jee-Bee » Wed Dec 13, 2017 5:02 am

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
Posts: 8345
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Cannot load GUI module in console application

Postby bernd » Wed Dec 13, 2017 6:11 am

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

Postby misterwazlib » Thu Jan 04, 2018 8:55 pm

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
Posts: 8345
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Cannot load GUI module in console application

Postby bernd » Fri Jan 05, 2018 5:04 am

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

Re: Cannot load GUI module in console application

Postby misterwazlib » Fri Jan 05, 2018 6:50 pm

Hi Bernd,

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

Re: Cannot load GUI module in console application

Postby Kunda1 » Fri Jan 05, 2018 8:14 pm

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
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
misterwazlib
Posts: 39
Joined: Mon Dec 04, 2017 10:05 pm

Re: Cannot load GUI module in console application

Postby misterwazlib » Fri Jan 05, 2018 8:18 pm

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
Posts: 8345
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Cannot load GUI module in console application

Postby bernd » Thu Jan 11, 2018 1:31 pm

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

Postby misterwazlib » Thu Jan 11, 2018 5:37 pm

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 1007 times