Auto constraint in sketcher

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
Grabeen Dyk
Posts: 2
Joined: Mon Sep 20, 2021 9:39 am

Auto constraint in sketcher

Post by Grabeen Dyk »

Absolute newbie to free cad <5 hours, but in my free time ive gotten interested in 3d modelling and wanted to try my hand at a simple keyboard plate(how i was wrong). After importing a DXF file of the plate, i set about creating the model. I took the draft into the draft workshop and made it a sketch, once that was done, i headed to the sketcher to check the constraints. lo and behold, I have 7000 degrees of freedom. although this may have been answered before, is there any way for me to do this automatically? Since if i have to do all 7000 manually im giving up

To anyone who helps thank you so much!

attached below is the image of my sketcher and the dxf file of my plate
Attachments
7c18a3476a59afc467da38d37a98214a3c99dafd_switch.dxf
(166.54 KiB) Downloaded 47 times
WhatsApp Image 2021-09-20 at 17.27.59.jpeg
WhatsApp Image 2021-09-20 at 17.27.59.jpeg (283.63 KiB) Viewed 1606 times
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Auto constraint in sketcher

Post by abdullah »

There are autoconstraining routines that can run from Python. But I think this guy:
easyw-fc wrote: Wed Oct 04, 2017 5:02 pm...
might have them implemented into the UI in his WB.
User avatar
papyblaise
Veteran
Posts: 8001
Joined: Thu Jun 13, 2019 4:28 pm
Location: France

Re: Auto constraint in sketcher

Post by papyblaise »

If you draw it with Fc, with which workshop, it seems to me Draft, why have it exported in DXF?
you have to do it in PartDesign> Sketcher
you make an outer rectangle, with the lower slit which is unique
then the keys by multiple copies
I leave you the pleasure of adding the constraints of dimensions
Attachments
keybord.FCStd
(208.2 KiB) Downloaded 43 times
keybord.PNG
keybord.PNG (4 KiB) Viewed 1567 times
chrisb
Veteran
Posts: 54201
Joined: Tue Mar 17, 2015 9:14 am

Re: Auto constraint in sketcher

Post by chrisb »

Grabeen Dyk wrote: Mon Sep 20, 2021 9:53 am lo and behold, I have 7000 degrees of freedom.
7000 DOF is far too much to be handled performantly. You should model this differently, e.g. by modeling one key, and then use clones of this.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Auto constraint in sketcher

Post by abdullah »

chrisb wrote: Mon Sep 20, 2021 9:52 pm
Grabeen Dyk wrote: Mon Sep 20, 2021 9:53 am lo and behold, I have 7000 degrees of freedom.
7000 DOF is far too much to be handled performantly. You should model this differently, e.g. by modeling one key, and then use clones of this.
For sure you are right. I wanted to test this with the autoconstraint routines just for fun:

Code: Select all

>>> ActiveSketch.detectMissingPointOnPointConstraints()
1904
>>> ActiveSketch.makeMissingPointOnPointCoincident()
>>> ActiveSketch.solve()
This reduced DoF to 3808 (it was fast).

Code: Select all

>>> ActiveSketch.detectMissingVerticalHorizontalConstraints()
1904
>>> ActiveSketch.makeMissingVerticalHorizontal()
>>> ActiveSketch.solve()
This reduced DoF to 1904 (it was fast).

Those work fine in a reasonable time (under one minute).

Afterwards, I tried to run the detection and creation of equalities.

The detection was very fast (1826) equalities detected, which would substantially lower the DoF. However, the algorithm seems to run a solve() for each pair (see below for reasoning). My computer had been running at that time for over one day with this task and it was not finished yet.

My lesson learnt was that it may make sense to add a parameter to the makeMissingEquality() so that a single solving is made at the end. So I went to the code, only to learn that I had already foreseen that and that the parameter is there (It is even documented!!!), so I tried passing False to it.

It took under 10 minutes to arrive to a heavily redundant system (and that was probably the reason for the solve after each, to remove redundants by pairs). However, deleting the redundants of this system is still running now (more than 12 hours later).

Apparently, I should look into improving this equality routine, as it is not well suited when many equal segments of a same length exist.

All in all, well working of autoconstraining for coincidents, horizontal and vertical and poor performance of equality autoconstraining (at least in this specific case).

For a reference to autoconstraining routines (there is a link to the Python documentation):
https://forum.freecadweb.org/viewtopic. ... 95#p260195

I wonder if somebody has used these routines and has some extra input... :?:
chrisb
Veteran
Posts: 54201
Joined: Tue Mar 17, 2015 9:14 am

Re: Auto constraint in sketcher

Post by chrisb »

Interesting test. I haven't used these routines, but have bookmarked your post :) .
I first wondered where the redundancies come from, but it is clear that every rectangle with coincidences, horizontal and vertical constraints will create them.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Grabeen Dyk
Posts: 2
Joined: Mon Sep 20, 2021 9:39 am

Re: Auto constraint in sketcher

Post by Grabeen Dyk »

Thanks for all the responses to my post, being a newb to this, i believe there are definitely things im missing in the creation of this. I may get back to this project in the future, but will be putting it on hold for now. I hope that in the future i will finally understand this, but in the mean time, i will be trying my best to understand freeCAD and your solutions
Post Reply