updating a sketch's constraints from python

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: updating a sketch's constraints from python

Post by openBrain »

CharlesM wrote: Tue Feb 07, 2023 10:52 am Since this thread was posted, is there a way to postpone the solver until every constraint have been modified ?
I investigated that recently following an issue with Lattice2 WB and my findings are that it's still not possible.
CharlesM
Posts: 15
Joined: Thu Feb 02, 2023 4:14 pm

Re: updating a sketch's constraints from python

Post by CharlesM »

Thank you very much for your help Carlo, this kind of resource is really helpful for new users like me. I will study these feasibilities when I’ll have more time.
OpenBrain , thank you for your interest in my problem ( again 😊 ) , I concluded that too . But the solver can be « tricked » to not reset the constraint value right away thus allowing to do what you want; I couldn’t come up with an example representative of my specific problem , but it should be enough to give an idea :
postfc1.png
postfc1.png (64.08 KiB) Viewed 373 times
Three circles, two tangents within a big one. The inner circle has a radius of 50 mm (label – small radius) , the outer circle has a radius of 100mm (label – big_radius) . A smaller circle is tangent between the others.

Let’s say that we wanted to upscale the whole sketch by a factor of three. We can do this :
1) Big_radius : 100 ==> 300
2) Small_radius : 50 ==> 150
But we cannot do that (as at some point, tangency would be broken) :
1) Small_radius : 50 ==> 150
2) Big_radius : 100 ==> 300

What bothered me was that the solver inside the sketcher force reset the constraint to their initial value. This behavior do not happens when the constraints are changed from outside the sketcher:

postfc2.png
postfc2.png (60.95 KiB) Viewed 373 times
And here the geometry will rebuild after the big radius has been modified


So I have two questions : Is there ongoing developments to mimick this behavior but inside the sketcher (such as group import of parameters found in some commercial cad software) ? . And the second one , how could i do it in the Pythonic way ? I did previously :

App.ActiveDocument.Sketch.setDatum(small_radius , goal value) .

But obviously, i could change them using the way shown in the second picture. (Unfortunately, the python console inside the gui stays empty when I do so)
CharlesM
Posts: 15
Joined: Thu Feb 02, 2023 4:14 pm

Re: updating a sketch's constraints from python

Post by CharlesM »

For those with the same problem : I did not find how to access the constraints as illustrated in the second picture of my previous post. But I managed to bypass the solver's immediate recompute by linking my sketch constraints to custom properties. (https://wiki.freecad.org/Property_editor)
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: updating a sketch's constraints from python

Post by openBrain »

CharlesM wrote: Thu Feb 09, 2023 10:40 am What bothered me was that the solver inside the sketcher force reset the constraint to their initial value. This behavior do not happens when the constraints are changed from outside the sketcher:
Actually the behavior happens less often. But there are still cases where it happens. ;)
@abdullah , may you know a tweak that would allow to call 'setDatum' without having the sketch to solve itself. I look at the calls in the code, and I didn't find anything obvious that could prevent this behavior.
Post Reply