I have successfully completed the tutorial regarding the creation of interfaces.
https://www.freecadweb.org/wiki/Manual: ... face_tools
I still have the problem, that the widget is not completely displayed (see picture), but that is something I postponed for the moment.
The problem I actually got stuck with is the following:
I want to extent the class of the example with properties for length, width and height so that it is possible to change the values later.
Based on this tutorial (https://www.freecadweb.org/wiki/Manual: ... ic_objects) I have tried to set the values using the values by:
Defining the property in the init section obj.addProperty("App::PropertyFloat","Length")
and changing the line from the interface tutorial:
Code: Select all
length = self.form.BoxLength.value()
Code: Select all
obj.Length = self.form.BoxLength.value()
Could please anybody give me a hint, how to connect the widget with the class properties in an elegant way?<unknown exception traceback><type 'exceptions.TypeError'>: accept() takes exactly 2 arguments (1 given)
Below is my current (not working) editing status of the interface tutorial:
Code: Select all
import FreeCAD, FreeCADGui, Part
# CHANGE THE LINE BELOW
path_to_ui = "/home/.../.../.../dialog.ui"
class PartFeature:
def __init__(self, obj):
obj.Proxy = self
class BoxTaskPanel():
def __init__(self,obj):
obj.addProperty("App::PropertyFloat", "Length")
# this will create a Qt widget from our ui file
self.form = FreeCADGui.PySideUic.loadUi(path_to_ui)
def accept(self,obj):
# length = fp.form.BoxLength.value()
obj.Length = self.form.BoxLength.value()
length = obj.Length
width = self.form.BoxWidth.value()
height = self.form.BoxHeight.value()
if (length == 0) or (width == 0) or (height == 0):
print("Error! None of the values can be 0!")
# we bail out without doing anything
return
box = Part.makeBox(length, width, height)
# Part.show(box)
# FreeCADGui.Control.closeDialog()
box.Placement = obj.Placement
obj.Shape = box
myObj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Box")
panel = BoxTaskPanel(myObj)
FreeCADGui.Control.showDialog(panel)
myObj.ViewObject.Proxy = 0
FreeCAD.ActiveDocument.recompute()
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.4.
Build type: Release
Python version: 2.7.15+
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Germany (de_DE)