So I'm trying to sort out how to watch another object for changes in it's properties. Essentially, I'm creating a FeaturePython object which takes a Line object as a child. I'm using the FeaturePython object to store metadata about the line, for example, it's bearing w.r.t the unit Y axis.
So, the Bearing property of the FP object, then, needs to update whenever the Line object changes...
Watching an object for property changes
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Watching an object for property changes
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
-
- Veteran
- Posts: 5513
- Joined: Thu Apr 05, 2018 1:53 am
Re: Watching an object for property changes
Should be able to use setExpression() to do it. For example, given an object named Cylinder and another named Line, if we wanted Cylinder's Height property to always be equal to Line's Y2 - Y1 value:
Code: Select all
App.ActiveDocument.Cylinder.setExpression('Height',u'Line.Y2-Line.Y1')
Re: Watching an object for property changes
What about using a App::PropertyLink property to have your FeaturePython object "triggered" when the Line object is changed :Joel_graff wrote: ↑Fri Jun 15, 2018 4:46 pm So I'm trying to sort out how to watch another object for changes in it's properties. Essentially, I'm creating a FeaturePython object which takes a Line object as a child. I'm using the FeaturePython object to store metadata about the line, for example, it's bearing w.r.t the unit Y axis.
So, the Bearing property of the FP object, then, needs to update whenever the Line object changes...
Code: Select all
class myFeaturePythonProxy(object):
def class __init__(self, fp):
fp.addProperty("App::PropertyLink", "LineObject", "myFP","Link to Line object")
fp.addProperty("App::PropertySomething", "Bearing", "myFP","Bearing")
def execute(self, fp):
# usually, execute is run whenever one of its child objects is touched.
update_bearing_property(fp)
# ... usual code here
def update_bearing_property(self, fp):
# check fp.LineObject properties
fp.Bearing = ... something
Re: Watching an object for property changes
you can simply install a document observer which is called when a object changes. I did not find a python example, but in the cpp file you can see the kind of functions that are exposed:
https://github.com/FreeCAD/FreeCAD/blob ... erPython.h
https://github.com/FreeCAD/FreeCAD/blob ... erPython.h
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
Re: Watching an object for property changes
Fascinating. I'll keep that in mind. I'm starting to sort the problem out, but if I can't solve it, this might do the trick...
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
- Joel_graff
- Veteran
- Posts: 1949
- Joined: Fri Apr 28, 2017 4:23 pm
- Contact:
[SOLVED] Watching an object for property changes
Solved this. The trick was to create a group object and add the object to be watched as a child. This triggers an auto update of the parent.
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers