You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在新空白文档加载FreeCAD UI时出现“Active task dialog found”错误的原因

问题描述

已确认FreeCAD GUI(基于Qt)不允许同时存在多个activeDialog实例,我只需要加载一个activeDialog。尝试在新的空白文档中调用代码,本以为不会有冲突的现有activeDialog控件,且代码里没有重复调用的情况,但我不知道如何查看当前文档中已存在的activeDialog。

我正在学习使用FreeCAD、PySide和Python(FreeCAD版本为3.10,系统是macOS 10.14),不管是手动写代码创建UI,还是用Qt Designer生成UI,都会遇到同样的问题,复制多个示例代码也无法解决。我知道问题很简单,但一直没找到原因。

错误信息:
执行代码行FreeCADGui.Control.showDialog(panel)时触发错误:

<class 'RuntimeError'>: Active task dialog found
相关代码
from PySide import QtGui, QtCore
import Part, PartGui
import FreeCAD as App

class OffsetCalc(QtGui.QDialog):
    
    def __init__(self):
        super(OffsetCalc, self).__init__()
        self.initUI()
    def __str__(self):
        return "OffsetCalc([])"
    def __str__(self):
        return "intUI([])"


    def initUI(self):
        self.result = userCancelled

    
        # setting font and size
        # create our window
        # define window     xLoc,yLoc,xDim,yDim
        self.setGeometry(   850, 550, 250, 250)
        self.setWindowTitle("Ship Offset Calculator")
        self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
        # creating a label widget
                # by default label will display at top left corner
 
        # The beginning of the coordinate system is at the left top corner. 
        # The x values grow from left to right. The y values grow from top to bottom.
        self.lSta = QtGui.QLabel("Station", self)
        self.lSta.setFont('Ariel') # set to a non-proportional font
        self.lSta.move(20, 20)

        
        self.lSta = QtGui.QLabel("H.B/W.L.", self)
        self.lSta.setFont('Ariel') # set to a non-proportional font
        self.lSta.move(20, 50)


        self.lSta = QtGui.QLabel("Feet", self)
        self.lSta.setFont('Ariel') # set to a non-proportional font
        self.lSta.move(20, 80)


        self.lSta = QtGui.QLabel("Inches", self)
        self.lSta.setFont('Ariel') # set to a non-proportional font
        self.lSta.move(20, 110)


        self.lSta = QtGui.QLabel("Eights", self)
        self.lSta.setFont('Ariel') # set to a non-proportional font
        self.lSta.move(20, 140)


        # numeric input field
        self.ista = QtGui.QLineEdit("Station", self)
        self.ista.setInputMask("999")
        #self.ista.setText("000")
        self.ista.setFixedWidth(50)
        self.ista.move(100, 20)

        self.iwlht = QtGui.QLineEdit(self)
        self.iwlht.setInputMask("999")
        #self.iwlht.setText("000")
        self.iwlht.setFixedWidth(50)
        self.iwlht.move(100, 50)

        self.ifeet = QtGui.QLineEdit(self)
        self.ifeet.setInputMask("999")
        #self.ifeet.setText("000")
        self.ifeet.setFixedWidth(50)
        self.ifeet.move(100, 80)

        self.iinch = QtGui.QLineEdit(self)
        self.iinch.setInputMask("999")
        #self.iinch.setText("000")
        self.iinch.setFixedWidth(50)
        self.iinch.move(100, 110)

        self.ieight = QtGui.QLineEdit(self)
        self.ieight.setInputMask("999")
        #self.ieight.setText("000")
        self.ieight.setFixedWidth(50)
        self.ieight.move(100, 140)


        self.bok = QtGui.QPushButton("OK", self)
        self.bok.clicked.connect(self.onbok)
        self.bok.move(20, 200)
                
        self.hbht = QtGui.QRadioButton("Calc H.B", self)
        self.hbht.move(150, 205)

        self.show()


    def onbok(self):
        sta = float(self.ista.text())
        wlht = float(self.iwlht.text())
        feet = float(self.ifeet.text())
        inches = float(self.iinch.text())
        eights = float(self.ieight.text())
        inches8 = inches*8 # number of 1/8's in Inches column
        dec_ft = (inches8 + eights)/96
        total_ft = feet + dec_ft

        # doc = App.activeDocument() 
        #p = Part.Point
        p = App.ActiveDocument.addObject("Part::Vertex", "p1")
        p.Y = sta # Station is always Y
        if self.hbht.isChecked:     #True =hb / False =ht
            # use calced X
            print("Using calc X")
            p.X = total_ft
            p.Z = wlht
        else:
            # use calced Z
            print("Using calc Z")
            p.X =  wlht 
            p.Z = total_ft
            
        App.ActiveDocument.recompute()

        # print("Station = ", sta, "Height = ", wlht, "Feet = ", feet, "Inches = ", inches, "Eights + ", eights)
        # print("Eights of Inches = ", inches8, "Dec Ft. = ", dec_ft, "Total = ", total_ft)
        self.result         = userOK
        self.close()

        doc=App.activeDocument() 
        p = Part.Point()
        p.Y = sta # Station is always Y
        if self.hbht.isChecked:     #True =hb / False =ht
            # use calced X
            print("Using calc X")
            p.X = total_ft
            p.Z = wlht
        else:
            # use calced Z
            print("Using calc Z")
            p.X =  wlht 
            p.Z = total_ft
            
        doc.recompute()

    def add_X_Point(self):
        doc=App.activeDocument() 
        p = Part.Point
        p.Y = Sta
        p.X = hb
        p.Z = total_ft 
        doc.recompute()
    

    def onCancel(self):
        self.result         = userCancelled
        self.close()
    def onOk(self):
        self.result         = userOK
        self.close()
    def mousePressEvent(self, event):
        # print mouse position, X & Y
        print("X = ", event.pos().x())
        print("Y = ", event.pos().y())
        #
userCancelled = "Cancelled"
userOK = "OK"

form = OffsetCalc()
form.exec_()

内容的提问来源于Stack Exchange,提问作者beachboy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 23:42:51