Notify other objects of a sketch object change

Need help, or want to share a macro? Post here!
Joel_graff
Posts: 784
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Notify other objects of a sketch object change

Postby Joel_graff » Mon Jan 14, 2019 9:00 pm

So I'm trying to figure out how to update other objects when a sketch they depend on is changed, much in the same way a sweep automatically updates after changing the dimensions of a sketch.

I have looked at SketchObjectPython, and I can see a way to possibly make it happen, but the approach I'm considering seems unnecessarily complicated.

Is there a straightforward way to accomplish that?
paullee
Posts: 1113
Joined: Wed May 04, 2016 3:58 pm

Re: Notify other objects of a sketch object change

Postby paullee » Wed Jan 16, 2019 3:46 am

Hope someone else would provide some feedback … though I thought it is 'automatic'?

I am using SketchObjectPython learnit from microelly / werner … there should be fp.recompute0 in def execute: Other objects depends on it would got recomputed also.

Anything I misunderstand?
Joel_graff
Posts: 784
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Notify other objects of a sketch object change

Postby Joel_graff » Wed Jan 16, 2019 4:35 am

paullee wrote:
Wed Jan 16, 2019 3:46 am
Hope someone else would provide some feedback … though I thought it is 'automatic'?

I am using SketchObjectPython learnit from microelly / werner … there should be fp.recompute0 in def execute: Other objects depends on it would got recomputed also.

Anything I misunderstand?
I have a situation that isn't a direct dependency. A sweep based on a sketch will automatically update - the sweep is directly dependent on the sketch. But I'm using a loft. The sections that make up the loft are wire polygons. Those polygons are generated from the sketch - so they are the wire equivalent of the sketch geometry.

But, they are independent of the sketch geometry. So if I change the sketch, the polygons will not update, and the loft will not change. So, I need a way to artificially connect them and was hoping it was possible to "watch" a sketch for changes.

I think I'll probably just maintain a LinkList in the SketchObjectPython of the lofts whose sections are built from it. Then, when the sketch changes, iterate the list and rebuilt the sections for the lofts to update them.
ickby
Posts: 2831
Joined: Wed Oct 05, 2011 7:36 am

Re: Notify other objects of a sketch object change

Postby ickby » Wed Jan 16, 2019 6:34 am

you could always use

Code: Select all

object.touch()
to inform a object that it needs to be recomputed.

General question: If your object does not have a link to the sketch, how does it know which sketch to use for rebuilding the polygons? Or if the polygons are individual objects, how do they know how to rebuild if they don't link to the sketch? You should explain your documen tstructure a bit more detailed.

What I could imagine is that you build "dump" polygons from the sketches which as objects don't know how they have been created. Is that correct? If this is the case, then the objects themself don't have any information how to be rebuild themself, and it is not enough to inform them of the sketch change, as they don't know which sketch to use for rebuild. (if they would know it as they have a link to sketch than freecad auto recompute would work). In this case you could keep the dependencie information somewhere else and use callbacks to rebuild. Have a look at Document Observers which you can setup and which inform you about changes to objects. You can than detect any change to the sketch, see in your dependency tracking if it relates to the polygons and rebuild polygons.