Issue while trying to run FreeCADGui from a Python script

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Lethalo
Posts: 10
Joined: Wed Sep 08, 2021 1:46 pm

Issue while trying to run FreeCADGui from a Python script

Post by Lethalo »

Hi everyone, I'm trying to run FreeCAD from Python script.

I'm getting an error with the code, which I found in the folder Tools/Embedded/PySide.
Here is the code I'm trying to run :

Code: Select all

import sys
from PySide2 import QtCore, QtGui, QtWidgets
import FreeCAD, FreeCADGui

class MainWindow(QtWidgets.QMainWindow):
    def showEvent(self, event):
        FreeCADGui.showMainWindow()
        self.setCentralWidget(FreeCADGui.getMainWindow())

app=QtWidgets.QApplication(sys.argv)
mw=MainWindow()
mw.resize(1200,800)
mw.show()

# must be done a few times to update the GUI
app.processEvents()
app.processEvents()
app.processEvents()

import Part
cube = Part.makeBox(2,2,2)
# creates a document and a Part feature with the cube
Part.show(cube)
app.processEvents()
app.processEvents()
FreeCAD shut itself down immedialty and this is the error I'm getting in the cmd :

Code: Select all

Traceback (most recent call last):
  File "minimal.py", line 22, in showEvent
    self.setCentralWidget(FreeCADGui.getMainWindow())
RuntimeError: Failed to wrap widget
Thank you for your reading, I hope I was clear enough :)
Post Reply