https://forum.freecad.org/viewtopic.php?p=670676
一次性清除所有参数,有点保护知识产权的意思。使用前必须备份。
import FreeCAD as App
from PySide import QtCore, QtGui
from PySide.QtGui import QLineEdit, QRadioButton
ExpObjects = []
class ExpressionRemover():
def __init__(self):
for i in App.ActiveDocument.Objects:
if i.isDerivedFrom("Part::Feature"):
if len(i.ExpressionEngine) != 0:
ExpObjects.append(i.Name)
if len(ExpObjects) == 0:
App.Console.PrintWarning('There are no Expressions to be removed\n')
else:
self.dialog = None
self.s1 = None
# Make dialog box
self.dialog = QtGui.QDialog()
self.dialog.resize(300,120)
self.dialog.setWindowTitle("Expression Remover")
la = QtGui.QVBoxLayout(self.dialog)
t1 = QtGui.QLabel("Choose to remove All expressions or specific objects in the combobox")
la.addWidget(t1)
# Add radio buttons
self.radio1 = QtGui.QRadioButton("All Object Expressions")
self.radio2 = QtGui.QRadioButton("Specific Objects")
self.radio1.clicked.connect(self.on_radio1_clicked)
self.radio2.clicked.connect(self.on_radio2_clicked)
# self.radio2.setChecked(True)
la.addWidget(self.radio1)
la.addWidget(self.radio2)
self.expObjs = QtGui.QComboBox()
self.expObjs.addItems(ExpObjects)
self.expObjs.setObjectName("expObjs")
self.expObjs.currentIndexChanged.connect(self.check_validity)
la.addWidget(self.expObjs)
# Add OK / Cancel buttons
self.okbox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel)
la.addWidget(self.okbox)
QtCore.QObject.connect(self.okbox, QtCore.SIGNAL("accepted()"), self.proceed)
QtCore.QObject.connect(self.okbox, QtCore.SIGNAL("rejected()"), self.close)
button = self.okbox.button(QtGui.QDialogButtonBox.Ok)
button.setEnabled(False)
QtCore.QMetaObject.connectSlotsByName(self.dialog)
self.dialog.show()
self.dialog.exec_()
def check_validity(self,idx):
App.Console.PrintLog("Current index %d selection changed %s\r\n" % (idx,self.expObjs.currentText()))
self.radio2.setChecked(True)
button = self.okbox.button(QtGui.QDialogButtonBox.Ok)
button.setEnabled(True)
def on_radio1_clicked(self):
button = self.okbox.button(QtGui.QDialogButtonBox.Ok)
button.setEnabled(True)
def on_radio2_clicked(self):
button = self.okbox.button(QtGui.QDialogButtonBox.Ok)
button.setEnabled(True)
def proceed(self):
if self.radio1.isChecked():
for i in App.ActiveDocument.Objects:
if i.isDerivedFrom("Part::Feature"):
if i.ExpressionEngine:
for j in i.ExpressionEngine:
i.setExpression(j[0], None)
App.ActiveDocument.recompute()
self.close()
if self.radio2.isChecked():
for i in App.ActiveDocument.Objects:
if i.Name == self.expObjs.currentText():
if i.ExpressionEngine:
for j in i.ExpressionEngine:
i.setExpression(j[0], None)
App.ActiveDocument.recompute()
self.close()
def close(self):
self.dialog.hide()
ExpressionRemover()