Clear all dependent parameters
Forum rules
and Helpful information
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help
Also, be nice to others! Read the FreeCAD code of conduct!
Also, be nice to others! Read the FreeCAD code of conduct!
Clear all dependent parameters
How to clear all dependent parameters of an object (or several objects) in a project at once? Cleaning manually turns out to be very long and you can miss something.
- Attachments
-
- Peek 2023-02-15 12-24.gif (435.52 KiB) Viewed 1143 times
Re: Clear all dependent parameters
Hello, this task can be achieved with a bit of python code
Code: Select all
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()
Re: Clear all dependent parameters
FreeCAD "macros" are just Python. You can save it in a file named mycoolcode.FCMacro or mycoolcode.py. Then you can execute it from the macro menu.
If you need it a lot you can also add it to one or more toolbars from the Tools>Customize menu.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
-
- Veteran
- Posts: 3192
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: Clear all dependent parameters
Code: Select all
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()
Re: Clear all dependent parameters
It's worked!
And if you need to clear a specific object, is it enough to substitute its internal name instead of App.ActiveDocument.Objects? Or, the syntax will be much more complicated?
And if you need to clear a specific object, is it enough to substitute its internal name instead of App.ActiveDocument.Objects? Or, the syntax will be much more complicated?
Re: Clear all dependent parameters
Here's what you really want (I hope):
Code: Select all
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()
Tested using:
Code: Select all
OS: Windows 7 Version 6.1 (Build 7601: SP 1)
Word size of FreeCAD: 64-bit
Version: 0.20.2.29177 +426 (Git)
Build type: Release
Branch: (HEAD detached from 0.20.2)
Hash: 930dd9a76203a3260b1e6256c70c1c3cad8c5cb8
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.3
Locale: English/United Kingdom (en_GB)
Installed mods:
* A2plus 0.4.60f
* Alternate_OpenSCAD 1.0.0
* Assembly3 0.11.4
* CfdOF 1.20.4
* Curves 0.6.6
* fasteners 0.4.54
* fcgear 1.0.0
* freecad.xray 2022.4.17
* FreeCAD_Turning_Addon 0.1.0
* Help 1.0.3
* Manipulator 1.5.0
* Plot 2022.4.17
* Render 2023.2.2
* sheetmetal 0.2.59
* Silk 1.0.0
* timber
Edit: I even made an icon for your toolbar
- Attachments
-
- ExpressionRemover.svg
- (10.28 KiB) Downloaded 18 times
Re: Clear all dependent parameters
This is exactly what was needed - your actions were ahead of my thoughts)
Can I somehow try to thank you?
Can I somehow try to thank you?
Re: Clear all dependent parameters
No need for special thanks, it's all part of the community chipping in and anyway it gave my brain a little workout which is no bad thing.