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

Re: Cannot load GUI module in console application

Post by misterwazlib »

Just to be clear, what I meant is that I would like to get the inp file (for example as attached here) as exported file.
Attachments
inp_file.txt
(160.08 KiB) Downloaded 86 times
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 »

two possibilities:

use the testmode which was implemented for unit tests: The sollowing works for me on FreeCAD 0.17.13005 (you have to have greater than 0.17.12995)

Code: Select all

import FreeCAD
docpath = FreeCAD.ConfigGet("AppHomePath") + "data/examples/FemCalculixCantilever3D.FCStd"
doc = FreeCAD.open(docpath)

for o in doc.Objects:
    print(o.Name)


analysis = doc.Analysis
solver = doc.CalculiX

from femtools import ccxtools
fea = ccxtools.FemToolsCcx(analysis, solver, test_mode=True)
fea.setup_working_dir()
error = fea.check_prerequisites()
fea.set_analysis_type("static")
error = fea.write_inp_file()



or use the solver frame work solver, but this is not yet tested well. See code in unit test how to run this: https://github.com/FreeCAD/FreeCAD/blob ... 1289-L1314

hope it helps bernd
misterwazlib
Posts: 39
Joined: Mon Dec 04, 2017 10:05 pm

Re: Cannot load GUI module in console application

Post by misterwazlib »

Many thanks for the help Bernd!
bernd wrote: Fri Jan 12, 2018 5:51 am two possibilities:

use the testmode which was implemented for unit tests: The sollowing works for me on FreeCAD 0.17.13005 (you have to have greater than 0.17.12995)

Code: Select all

import FreeCAD
docpath = FreeCAD.ConfigGet("AppHomePath") + "data/examples/FemCalculixCantilever3D.FCStd"
doc = FreeCAD.open(docpath)

for o in doc.Objects:
    print(o.Name)


analysis = doc.Analysis
solver = doc.CalculiX

from femtools import ccxtools
fea = ccxtools.FemToolsCcx(analysis, solver, test_mode=True)
fea.setup_working_dir()
error = fea.check_prerequisites()
fea.set_analysis_type("static")
error = fea.write_inp_file()
This works perfectly, however I still don't knw how to export the generated inp file. When I run your code in the console mode I can't see the inp text anywhere.

I tried to export it with

Code: Select all

import Fem
Fem.export(u"C:/FreeCAD_0.17.13005_x64_dev_win/test.inp")
but I don't see the file test.inp anywhere in the directory
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 »

set working with no argument sets the working path to your working path pref. Pass a path if you would like to use a diffetent one. The used working path is returned and printed. Your inp file will be in this path.

post the output off my code if you gone run it.
misterwazlib
Posts: 39
Joined: Mon Dec 04, 2017 10:05 pm

Re: Cannot load GUI module in console application

Post by misterwazlib »

bernd wrote: Fri Jan 12, 2018 9:51 pm post the output off my code if you gone run it.
ah I didn't read the output thoroughly, the inp file is there in the working directory :mrgreen:

many thanks again for your help!

anyway you told me to post the output so here it is

Code: Select all

>>> import FreeCAD
>>> docupath = FreeCAD.ConfigGet("AppHomePath") + "result.FCStd"
>>> 
>>> docu = FreeCAD.open(docupath)
>>> App.setActiveDocument("result")
>>> App.ActiveDocument=App.getDocument("result")
>>> Gui.ActiveDocument=Gui.getDocument("result")
>>> 
>>> for o in docu.Objects:
...     print(o.Name)
... 
cube
Analysis
Calculix
SolidMaterial
FemConstraintDisplacement
FemConstraintInitialTemperature
FemConstraintHeatflux
FEMMeshGMSH
>>> 
>>> analysis = docu.Analysis
>>> solver = docu.Calculix
>>> 
>>> from femtools import ccxtools
>>> fea = ccxtools.FemToolsCcx(analysis, solver, test_mode=True)
Dir 'C:/FreeCAD_0.17.13005_x64_dev_win/bin/ccx.exe\' doesn't exist and cannot be created.
Dir 'c:\users\diodwi~1\appdata\local\temp' will be used instead.
FemToolsCCx.setup_working_dir()  -->  self.working_dir = c:\users\diodwi~1\appdata\local\temp
>>> fea.setup_working_dir()
Dir 'C:/FreeCAD_0.17.13005_x64_dev_win/bin/ccx.exe\' doesn't exist and cannot be created.
Dir 'c:\users\diodwi~1\appdata\local\temp' will be used instead.
FemToolsCCx.setup_working_dir()  -->  self.working_dir = c:\users\diodwi~1\appdata\local\temp
>>> error = fea.check_prerequisites()
SolidMaterial has Solid reference shapes.
>>> fea.set_analysis_type("thermomech")
>>> error = fea.write_inp_file()
FemInputWriterCcx --> self.dir_name  -->  c:\users\diodwi~1\appdata\local\temp\
FemInputWriterCcx --> self.main_file_name  -->  FEMMeshGMSH.inp
FemInputWriterCcx --> self.file_name  -->  c:\users\diodwi~1\appdata\local\temp\FEMMeshGMSH.inp
Constraint displacement: FemConstraintDisplacement
  nodes will be retrieved by searching the appropriate nodes in the FEM mesh
  ReferenceShape ... Type: Face, Object name: cube, Object label: cube, Element name: Face1
Writing time input file: 0.119304669422 

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 »

:)

if you pass a path with set working dir you can set it to any dir you like

Code: Select all

fea.setup_working_dir('YourOwnSpecialInputFilePath')
misterwazlib
Posts: 39
Joined: Mon Dec 04, 2017 10:05 pm

Re: Cannot load GUI module in console application

Post by misterwazlib »

bernd wrote: Mon Jan 15, 2018 1:08 pm :)

if you pass a path with set working dir you can set it to any dir you like

Code: Select all

fea.setup_working_dir('YourOwnSpecialInputFilePath')
top! :D :D
raphael553
Posts: 1
Joined: Tue Aug 11, 2020 4:04 pm

Re: Cannot load GUI module in console application

Post by raphael553 »

Hello everybody,

I've tried to run bernd's test mode script and then got this error message:

Code: Select all

Traceback (most recent call last):              (100.0 %)
  File "test.py", line 14, in <module>
    solver = doc.CalculiX
AttributeError: 'App.Document' object has no attribute 'CalculiX'
How can we solve it? Thanks in advance!
Post Reply