Complex curved shapes with FreeCAD - Sweep along two rails with Sketcher, Part and Python

A place to share learning material: written tutorials, videos, etc.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
j8sr0230
Posts: 140
Joined: Thu Apr 07, 2022 8:59 am
Location: Chemnitz
Contact:

Complex curved shapes with FreeCAD - Sweep along two rails with Sketcher, Part and Python

Post by j8sr0230 »

Hi everyone,
i recently posted my ornament project in the Users Showcase (call for screenshots). I used the following FreeCAD version:

Code: Select all

OS: Windows 10 (10.0)
Word size of FreeCAD: 64-bit
Version: 0.20.28611 (Git)
Build type: Release
Python 3.8.13, Qt 5.12.9, Coin 4.0.0, OCC 7.5.3
Locale: German/Germany (de_DE)
Installed mods: 
  * CurvedShapes 1.0.1
  * Curves 0.3.0
  * DynamicData 2.45.0
  * fasteners 0.3.38
  * ThreadProfile 1.81.0
Following a request from the forum member chrisb, I would like to share with you a simple technique I use to model complex ornamental structures for 3D printing or milling with FreeCAD (see pictures below).
Ornament modeled with FreeCAD, rendered with Blender
Ornament modeled with FreeCAD, rendered with Blender
2022-04-08_Ornament_with_FreeCAD.jpg (118.74 KiB) Viewed 3117 times
This technique produces error-free solids and can be used as an alternative to Chris_G's excellent Sweep2Rails command of the Curves Workbench. All you need is the Sketcher, the Part Workbench and my little Python script DistibuteProfilesOnRails.FCMacro (see attachment). This macro can be used to sweep a profile allong two rails. As a requirement, you need the profile sketch mapped to the rails sketch via external support lines. You can find step-by-step instructions in the attached PDF documentation. The macro basically performs a deep copy of the profile sketch and moves the copy along the rails sketch using the mapping parameters of the support lines. It creates a group folder with the generated profiles. What you do with the profiles is up to you. I usually loft them manually or with another macro of mine for comfortable lofting of profile groups.

I also have a technique and macro for adjusting profile dimensions (height, width or other profile details) along the mapping parameters for even more shape control during modeling by mapping function values to the generated profiles (comparable to the float curve mapping widget of Blender). Just let me know if you are interested in further hints and instructions.

Have fun with the tutorial.
Attachments
2022-04-08_Sweep2_doc_by_j8sr0230.pdf
Sweep2 documentation
(723.07 KiB) Downloaded 164 times
2022-04-08_Sweep2_by_j8sr0230.FCStd
FreeCAD file
(68.79 KiB) Downloaded 107 times
DistributeProfilesOnRails.FCMacro
DistributeProfilesOnRails Macro
(2.47 KiB) Downloaded 108 times
Last edited by j8sr0230 on Fri Apr 08, 2022 12:59 pm, edited 3 times in total.
Codelink on GitHub: https://github.com/j8sr0230/codelink
Codelink on PiPy: https://pypi.org/project/codelink/
FreeCAD Nodes Workbench on GitHub: https://github.com/j8sr0230/Nodes
chrisb
Veteran
Posts: 53945
Joined: Tue Mar 17, 2015 9:14 am

Re: Complex curved shapes with FreeCAD - Sweep along two rails with Sketcher, Part and Python

Post by chrisb »

Thanks! Will have a look at it later.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
ifohancroft
Posts: 205
Joined: Fri May 31, 2019 11:25 pm
Location: Sofia, Bulgaria
Contact:

Re: Complex curved shapes with FreeCAD - Sweep along two rails with Sketcher, Part and Python

Post by ifohancroft »

Thank you! That's word censored awesome!
I like making, breaking and modding stuff, using a soldering iron, code or both. https://ifohancroft.com
User avatar
ragohix769
Posts: 565
Joined: Sat Jul 18, 2020 7:04 am
Location: Rome - Italy

Re: Complex curved shapes with FreeCAD - Sweep along two rails with Sketcher, Part and Python

Post by ragohix769 »

ifohancroft wrote: Fri Apr 08, 2022 1:46 pm word censored awesome!
ROTFL :-)
After #ElonMuskBuyTwitter I'm no more on Twitter, that's really enough :-(
=> Now you can find me here on #Mastodon: https://mastodon.uno/@opensoul - I hope more people do the same :-)
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

Re: Complex curved shapes with FreeCAD - Sweep along two rails with Sketcher, Part and Python

Post by paullee »

Really awesome 8-)
User avatar
hammax
Veteran
Posts: 1985
Joined: Thu Jan 19, 2017 5:03 pm
Location: Ammersee DE

Re: Complex curved shapes with FreeCAD - Sweep along two rails with Sketcher, Part and Python

Post by hammax »

... could there be implemented also a feature, to control a variable (expression e.g.) profile height.
Tried it with an own example, but my file doesn't produce the profile array??

FC.20
FC.20
Ornament_Sweep.PNG (28.44 KiB) Viewed 2723 times
Attachments
SweepProfiles.FCStd
(32.25 KiB) Downloaded 51 times
User avatar
j8sr0230
Posts: 140
Joined: Thu Apr 07, 2022 8:59 am
Location: Chemnitz
Contact:

Re: Complex curved shapes with FreeCAD - Sweep along two rails with Sketcher, Part and Python

Post by j8sr0230 »

Hi hammax,
thanks for your feedback. I have looked at your file. You have added an additional condition when mapping the support lines, that prevents FreeCAD from moving the profiles along the rails (see figure).
Correct mapping of support lines for profile generation
Correct mapping of support lines for profile generation
Correct mapping of support lines.png (568.62 KiB) Viewed 2674 times
For manipulating sketch parameters such as profile height along the rails, I also wrote a macro that reads out the Y-function values of an additional b-spline and maps them to the desired profile parameter. To do this, you simply add a b-spline to a new sketch and manipulate the curve according to your wishes. Name this sketch after the profile parameter you want to manipulate. First select the profile group, then the mapper sketch and start the macro MapParameter.FCMacro. This means that you can use the b-spline in the mapper sketch to dynamically manipulate sketch parameters such as the profile height along the rails. I have put together the complete setup as an example for you (see figure and attached files).
Curve mapping of sketch dimensions
Curve mapping of sketch dimensions
Curve mapping.png (916.72 KiB) Viewed 2674 times
In addition to this I have the macro LotGroup.FCMacro for comfortable lofting of whole profile groups. Just click on the automatically generated profile group and start the macro. Afterwards you get automatically the desired ParaSolid. The macro documentation still leaves something to be desired, but I'm working on it ...

Have fun with the files and a nice rest of the weekend!
Attachments
2022-04-10_Sweep2_with_parameter_mapping.FCStd
Your demo file
(234.06 KiB) Downloaded 68 times
MapParameter.FCMacro
Macro MapParameter.FCMacro
(1.82 KiB) Downloaded 63 times
LoftGroup.FCMacro
Macro LoftGroup.FCMacro
(831 Bytes) Downloaded 68 times
Codelink on GitHub: https://github.com/j8sr0230/codelink
Codelink on PiPy: https://pypi.org/project/codelink/
FreeCAD Nodes Workbench on GitHub: https://github.com/j8sr0230/Nodes
User avatar
hammax
Veteran
Posts: 1985
Joined: Thu Jan 19, 2017 5:03 pm
Location: Ammersee DE

Re: Complex curved shapes with FreeCAD - Sweep along two rails with Sketcher, Part and Python

Post by hammax »

... up to now I didn't test the profile height mapping - was glad enough to get the profile Loft.
The orientation of the profile cuts is still a riddle - is it somehow controllable.
Any relevance to SurfaceWB?

Ornament_Sweep_2.PNG
Ornament_Sweep_2.PNG (22.8 KiB) Viewed 2621 times
Attachments
Profile_parameter_mapping.FCStd
FC.20
(44.64 KiB) Downloaded 57 times
User avatar
j8sr0230
Posts: 140
Joined: Thu Apr 07, 2022 8:59 am
Location: Chemnitz
Contact:

Re: Complex curved shapes with FreeCAD - Sweep along two rails with Sketcher, Part and Python

Post by j8sr0230 »

Apparently, B-splines are not parameterized linearly in FreeCAD. By manipulating B-Spline control points, the parameterization can be adjusted. Since the support lines are mapped to the B-splines via this parameterization, the orientation can be manipulated after the generation of the profiles by moving individual control points. If the control points are arranged smartly, this usually works without changing the path of the rail (see picture below).
Cross section orientation.png
Cross section orientation.png (641.67 KiB) Viewed 2596 times
I've only been a member of the FreeCAD forum for a few days, so I can't accurately assess whether this technique or my macros are relevant to the Surface WB. I use my technique as an extended/improved sweep command. Possibly an addition to the Part WB?
Codelink on GitHub: https://github.com/j8sr0230/codelink
Codelink on PiPy: https://pypi.org/project/codelink/
FreeCAD Nodes Workbench on GitHub: https://github.com/j8sr0230/Nodes
User avatar
hammax
Veteran
Posts: 1985
Joined: Thu Jan 19, 2017 5:03 pm
Location: Ammersee DE

Re: Complex curved shapes with FreeCAD - Sweep along two rails with Sketcher, Part and Python

Post by hammax »

... WOW all your Macro proposals are working parametric !!!
Thickness of profile by Height Sketch, Loft generation
and orientation of profiles by BSpline control point arrangement.
Thanks

Ornament_Sweep_3.PNG
Ornament_Sweep_3.PNG (25.6 KiB) Viewed 2538 times
Attachments
Profile_parameter_mapping_2.FCStd
FC.20
(46.3 KiB) Downloaded 60 times
Post Reply