I investigated that recently following an issue with Lattice2 WB and my findings are that it's still not possible.
updating a sketch's constraints from python
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: updating a sketch's constraints from python
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 : 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:
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)
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 : 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:
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)
Re: updating a sketch's constraints from python
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)
Re: updating a sketch's constraints from python
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.