Constraining Sketch polygon to external geometry (hexagon)

A place to share learning material: written tutorials, videos, etc.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
sdaau_ml
Posts: 35
Joined: Fri Dec 07, 2018 12:18 am

Constraining Sketch polygon to external geometry (hexagon)

Post by sdaau_ml »

NOTE: Originally I was writing this as a question, since when I was trying to do this originally, the process ended with the Sketch solver asking me to remove almost all of my constraints (!) So I tried to explain exactly what I did through an example, so I can get a solution to that - and as I was writing this example, it ended successfully, with a "Fully constrained sketch" (!!) So since I went through the trouble of writing this, I might as well keep it here, as a tutorial of sorts for new users - hope that's OK!

-------

Hi all,

Code: Select all

OS: Ubuntu 18.04.1 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15379 (Git)
Build type: Release
Branch: master
Hash: 3290c36d28551875f02333c2e01af80e38b8ad02
Python version: 2.7.15rc1
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)
I would like to align a Sketcher polygon (here hexagon) to external geometry from a STEP file, such that the polygon is valid (closed) for further extrude. Here is an example
  • Get ISO4032_Hex_Nut_M3.step
  • Open new FreeCAD document
  • File/Import ISO4032_Hex_Nut_M3.step
  • Save FreeCAD document as, say, /tmp/test-ext.fcstd
  • The imported object is called Chamfer; select it in tree view, in Properties View/Data change Placement/Position z to 50 mm:
freecad-01.png
freecad-01.png (103.23 KiB) Viewed 2650 times
Now let's make a surface object, to whose face I want to assign the future Sketch to:
  • Go to Draft WB
  • Make sure you have Top view set, and current working plane set to Top
  • Select Rectangle Tool
  • Draw a Draft rectangle around the hex nut, e.g. from -15, 10 (, 0) to 30, -20 (, 0)
  • Go to Part WB; have the new Rectangle node in Tree View selected, then click Part/Extrude; accept default settings, click Apply in Tasks,
  • click Close in Tasks - now you have a new node, Extrude, instead of Rectangle in Model tree view
  • Tilt the 3D view a bit to make sure everything makes sense so far
freecad-02.png
freecad-02.png (142.79 KiB) Viewed 2650 times
  • Go to Sketcher WB
  • Switch to Bottom view
  • Select the bottom face of the Extrude object, then click Sketch/Create Sketch
  • Keep FlatFace for "Select the method to attach this sketch to selected object", hit OK
  • The new Sketch opens automatically in Sketch editor
Here is where it gets a bit tricky, since our Extrude object sits in the view of our imported hex nut (and Sketcher always turns the associated object's visibility ON when opening a Sketch in the sketch editor):
freecad-03.png
freecad-03.png (88.93 KiB) Viewed 2650 times
..., and so we wouln't be able to click and select external geometry. So at this point, don't leave the sketch editor (via Close in Tasks), but simply
  • Switch the Combo View tab back to Model:
  • Select the Extrude object node
  • Hit [SPACE] so it hides
  • Switch back the Combo View tab back to Tasks
Now we can see our hex nut; lets try to import its edges via external geometry
  • Zoom in view appropriately
  • Choose Sketch/Sketcher geometries/External geometry
  • With the new tool you get at your mouse pointer, try to click on the hexagon edges of the hex nut, to add them as external geometry
  • When done, hit ESC to exit External geometry node (careful, if you hit ESC one more time, you will exit the sketch editor too)
In this example, there will be a total of 12 external edges, two for each side of the hexagon:
freecad-04.png
freecad-04.png (116.74 KiB) Viewed 2650 times
⠀⠀⠀⠀

First problem: what we think are single points connecting edges of the hexagons, are actually two distinct points - zoom in on the point visible on the previous screenshot, and eventually you'll see this:
freecad-05.png
freecad-05.png (110.55 KiB) Viewed 2650 times
⠀⠀⠀⠀

So know I'm not really sure what would be the right way to trace out this hexagon. For one, I guess if one could extend the external hexagon edges a bit, they will eventually meet at a point, which will be the "real" point of the hexagon - but I cannot really tell if its possible (and straightforward) to do this in Sketcher; ideas are appreciated.

Anyways, the Sketch/Sketcher geometries/Create hexagon tool, will anyways automatically add a construction geometry (blue) circle, and lines with constraints based on that, to construct the hexagon; and it is used the same as Sketch/Sketcher geometries/Create circle (by its center and by a rim point).

So I was thinking this - click approx in the area of the center of the hexagon (here we have the benefit of having the Origin point in the center, but we might not have it in a different context), drag to approx end of the hexagon, then constrain points of the hexagon with points of the external geometry on opposing ends - so at least this should give a hexagon of matching size.

So, after placing a hexagon with Sketch/Sketcher geometries/Create hexagon tool, I might have something like this (moving to imgur, 5-file attachment limit hit):

Image

Let's zoom in on the top points, say. What you'd need to do here is a box select (click and drag) over the points connecting edges - from certain directions of dragging the box select (indicated on screenshot below), edges are included in the selection, from others they are not! With a bit of experimentation, it will happen that you manage to select both points forming a point between edges - use the Selection view panel to confirm that:

Image

Then, in this example at least, you can zoom in to the points of the external edges, and Ctrl-Click one of them to add them to the selection (in another file I worked with, it was impossible to Ctrl-Click these points, one **had** to do Box select!) - here it's sort of visible I've chosen the one a bit to the right:

Image

Now, with three points selected, I click "Create a coincident constraint on the selected item" - and the points indeed connect:

Image

Change the view down to the opposite end, and do the same - choose again the external edge point "to the right", so we have the same diameter as the external hexagon:

Image

Note at this point, the Sketch hexagon lines turned green, to note that the sketch is fully constrained. If we zoom out, we can see that we have a quite OK alignment of the Sketch hexagon with the external hexagon:

Image

It is also noted in the solver that this is a "Fully constrained sketch"

Finally, we can exit Sketch editor mode via Close in Tasks, give the Extrude object transparency of 70%, select the Sketch in Model Tree view, and observe that indeed we have a match:

Image

As a final step, you can go to Part Design WB, choose Part Design/Validate sketch... which will tell you "No missing coincidences found", and will not highlight anything when you click "Highlight open vertexes".

EDIT: In the end, having gone through all this, it is clear we didn't even need to import all twelve external edges - just two that would specify the top and bottom point to align to, would have been enough (left as exercise to the reader)
Last edited by sdaau_ml on Thu Dec 20, 2018 8:55 pm, edited 2 times in total.
User avatar
HarryGeier
Veteran
Posts: 1231
Joined: Mon Jul 10, 2017 12:36 pm
Location: Hof Germany

Re: Constraining Sketch polygon to external geometry

Post by HarryGeier »

All fine but i think it should be posted in the "videos and tutorials" section instead of "help"

harry
Kaum macht man´s richtig , gehts´s
My Video Tutorials on Youtube: https://www.youtube.com/channel/UCoe3B ... p8Q/videos
My FreeCAD Stuff on Hidrive: https://my.hidrive.com/share/qr3l1yddy6#$/
chrisb
Veteran
Posts: 54207
Joined: Tue Mar 17, 2015 9:14 am

Re: Constraining Sketch polygon to external geometry

Post by chrisb »

sdaau_ml wrote: Thu Dec 20, 2018 1:13 am NOTE: Originally I was writing this as a question, since when I was trying to do this originally, the process ended with the Sketch solver asking me to remove almost all of my constraints (!)
I am sure the solver never did this. He probably told you that you should remove one of them and listed them all. By clicking on the link you selected them all and removed them.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
sdaau_ml
Posts: 35
Joined: Fri Dec 07, 2018 12:18 am

Re: Constraining Sketch polygon to external geometry

Post by sdaau_ml »

Thanks guys,
HarryGeier wrote: Thu Dec 20, 2018 6:39 pm All fine but i think it should be posted in the "videos and tutorials" section instead of "help"
Sure - sorry about that, I just ended up posting it here, because I started writing it as a question.

Do I have permissions to make that move? If not, if there's a forum admin around, feel free to make that move, I'm OK with that.
chrisb wrote: Thu Dec 20, 2018 8:29 pm I am sure the solver never did this. He probably told you that you should remove one of them and listed them all. By clicking on the link you selected them all and removed them.
Ah indeed - thanks for clarifying that :)
chrisb
Veteran
Posts: 54207
Joined: Tue Mar 17, 2015 9:14 am

Re: Constraining Sketch polygon to external geometry

Post by chrisb »

Here are some comments in case you are interested.

I would recommend a workflow with a smaller set of tools. Oldies know how to do this anyway, newbies should not have to struggle more than necessary. So I would not use Draft WB to create the first block, but Sketcher as well.
Next I would not attach the sketch to the bottom face but rather to the standard plane.
Here is where it gets a bit tricky, since our Extrude object sits in the view of our imported hex nut (and Sketcher always turns the associated object's visibility ON when opening a Sketch in the sketch editor):
You can control this in Sketcher's preferences.
So know I'm not really sure what would be the right way to trace out this hexagon. For one, I guess if one could extend the external hexagon edges a bit, they will eventually meet at a point, which will be the "real" point of the hexagon - but I cannot really tell if its possible (and straightforward) to do this in Sketcher; ideas are appreciated.
It is sufficient to view only one corner:
- create the hexagon with the center in the origin
- create a point on line constraint with point from the external geometry and line from the hexagon
- do the same with the adjacent edges
and you are done, no coincidence needed. The image shows the detail. I can attach the file in case you are interested.
Attachments
Bildschirmfoto 2018-12-20 um 23.23.13.png
Bildschirmfoto 2018-12-20 um 23.23.13.png (14.14 KiB) Viewed 2587 times
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
chrisb
Veteran
Posts: 54207
Joined: Tue Mar 17, 2015 9:14 am

Re: Constraining Sketch polygon to external geometry (hexagon)

Post by chrisb »

If you want to remove the small face before creating the sketch you can use Part->Defeaturing (requires 0.18 and OCC >= 7.3).
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Post Reply