Showmainwindow not working in freecadcmd

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
carlos.costacano
Posts: 10
Joined: Fri Mar 24, 2023 8:17 pm

Showmainwindow not working in freecadcmd

Post by carlos.costacano »

Hello

I have been playing around with FreeCAD for a while now, this time I don't know how to solve this problem

my main goal is to automate certain tasks with FreeCAD, and I would like to use freeCADcmd, so I can make the calls from anywhere I want, but when I try to show the GUI with Gui.showMainWindow() I get this in the log

Code: Select all

Log: All modules with GUIs using InitGui.py are now initialized
Log: All modules with GUIs initialized using pkgutil are now initialized
Log: Init: Loading FreeCAD GUI
Log: Init: Running FreeCADGuiInit.py start script... done
Log: Init: Activating default workbench 
Log: Loading GUI of Web module... done
Log: Loading GUI of Start module... done
Log: Loading Start module... done
Log: WebEngineContext used before QtWebEngine::initialize() or OpenGL context creation failed.
Err: Exception while processing file: C://Development//Qt//mainwindow//test.py [Illegal storage access! Please save your work under a new file name and restart the application!]
Log: Exiting on purpose
Log: FreeCAD terminating...
looking for this error in internet seems related with Qt

Is there anyway to use the FreeCAD instance that is already open?

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.2.29603 (Git)
Build type: Release
Branch: releases/FreeCAD-0-20
Hash: 930dd9a76203a3260b1e6256c70c1c3cad8c5cb8
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.3
Locale: English/New Zealand (en_NZ)
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Showmainwindow not working in freecadcmd

Post by onekk »

If use freecadcmd you have no Gui as it is the headless version of FreeCAD, you could import FreeCADGui, there are some hints probably on the wiki in the power users section.

And in some old @wmayer posts.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
wmayer
Founder
Posts: 20242
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Showmainwindow not working in freecadcmd

Post by wmayer »

Log: WebEngineContext used before QtWebEngine::initialize() or OpenGL context creation failed.
I do get this warning too but FreeCAD doesn't crash.
Err: Exception while processing file: C://Development//Qt//mainwindow//test.py [Illegal storage access! Please save your work under a new file name and restart the application!]
I wonder what is test.py doing? Could this be the culprit doing something forbidden?

To rule out the Start module as the problem you can change your start workbench. Therefore start FreeCAD normally and change the default startup workbench in the preferences. Then try FreeCADCmd again.
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: Showmainwindow not working in freecadcmd

Post by Syres »

wmayer wrote: Tue Mar 28, 2023 10:09 am I do get this warning too but FreeCAD doesn't crash.
I've been having a look at an issue issue #9086 and it can't be a coincidence that testing the two builds quoted in reply produce the same results in that Version: 0.21.31155 (Git) Approx 2nd Dec 2022 starts a main window in FreeCADcmd:

Code: Select all

import FreeCADGui as Gui
Gui.showMainWindow()
but following the same procedure with Version: 0.21.0.31850 (Git) Approx 12th Feb 2023 produces the

Code: Select all

<Exception> Access Violation
You'll note the git commit 2f575a3 is the one that stood out to me as it's Windows specific but that's purely a hunch.
carlos.costacano
Posts: 10
Joined: Fri Mar 24, 2023 8:17 pm

Re: Showmainwindow not working in freecadcmd

Post by carlos.costacano »

wmayer wrote: Tue Mar 28, 2023 10:09 am
Log: WebEngineContext used before QtWebEngine::initialize() or OpenGL context creation failed.
I do get this warning too but FreeCAD doesn't crash.
Err: Exception while processing file: C://Development//Qt//mainwindow//test.py [Illegal storage access! Please save your work under a new file name and restart the application!]
I wonder what is test.py doing? Could this be the culprit doing something forbidden?

To rule out the Start module as the problem you can change your start workbench. Therefore start FreeCAD normally and change the default startup workbench in the preferences. Then try FreeCADCmd again.
sorry I forgot to put this code of test.py, is just

Code: Select all

import FreeCADGui as Gui

Gui.showMainWindow()
I have changed the start workbench to none and still happens
carlos.costacano
Posts: 10
Joined: Fri Mar 24, 2023 8:17 pm

Re: Showmainwindow not working in freecadcmd

Post by carlos.costacano »

I have been looking into this problem, looks like showMainWindow may work or not depending on the system and version because it is not intended to work in this way in freecadcmd

I have seen other people trying this way, because it is a good way to develop a bigger app that uses FreeCAD in the background for some aspect of the app but not being the main part

I already started a workbench development to do what I need, the first problem I face is how to install other pyhton modules I need, I don't find a clear explanation how to do this, other post suggest to paste the library folders in the correspondent FreeCAD sitepackages, this has worked for the the first library I need, but it may not work with others I may need in the future, I have found older post talking about this but not official way of doing it

i would like to suggest to improvements for FreeCAD:

-embedding FreeCAD in other Apps
-install extra libraries in FreeCAD
CharlesM
Posts: 15
Joined: Thu Feb 02, 2023 4:14 pm

Re: Showmainwindow not working in freecadcmd

Post by CharlesM »

Hello,

Any improvement on this problem @carlos.costacano ? At my work we are facing the same issue. We are developing a FreeCAD/Qt app and for some reason, it wont works on some computer.

From inside freecadcmd.exe :

Code: Select all

import FreeCADGui as Gui
Gui.showMainWindow()
Just fails.

We tried to update them from Windows 10 to 11 without success. On other computers, it works flawlessly.

Any suggestions ?

EDIT : We just checked , it seems to be a bug on the release Version: 0.20.2.29603 (Git) , we downgraded to Version: 0.20.2.29177 +426 (Git) , and it seems to work.
carlos.costacano
Posts: 10
Joined: Fri Mar 24, 2023 8:17 pm

Re: Showmainwindow not working in freecadcmd

Post by carlos.costacano »

thanks for the info

I have started the development of a workbench after not being able to solve it, I don't think I am going to try the other way for a while
Post Reply