Skip to main content

Curve Workbench Macro: Curve to Freehand B-Spline

FreeCAD Macro: Create Freehand B-Spline from a Selected Curve

If you're exploring FreeCAD macros or looking to replicate Rhino3D’s tween curve functionality, this guide will walk you through how to create a freehand B-spline from a selected curve using the Curves workbench.

This macro is part of an ongoing effort to bring more organic, editable curve control into FreeCAD.

Goal: Convert a Selected Curve to a Freehand B-Spline

The first step in this project is converting a selected edge or curve into a freehand B-spline, not directly connected, but one that follows the curvature of the original.

This allows for more flexible editing and prepares us for the next stages, like applying this to ISO curves on a surface and generating multiple B-splines per edge.

Watch the Macro in Action

Here’s an unlisted video showing the macro in use:
https://youtu.be/fycOs-0Oy8M

What Is "Discretize" and Why Use It?

To build a B-spline, we first discretize the edge. This simply means:

“Dividing geometry into finite elements, often to prepare for analysis.”

We extract a set number of 3D coordinate points from the original curve and use them as control points for the new editable B-spline. The original curve is then discarded.

This process bridges mathematical complexity with practical CAD modeling.

Macro Code: From Curve to Editable B-Spline

Here’s the final macro (FreeCAD Python) that performs the conversion:

from freecad.Curves import gordon_profile_FP as GP 

# Increase this for better curve-following
numberOfControlPoints = 6 

# Get edge from selection
edge = Gui.Selection.getSelectionEx()[0].SubObjects[0] 

# Discretize edge into points
pts = edge.discretize(Number=numberOfControlPoints) 
typ = [0] * numberOfControlPoints 

# Create the B-spline object
fp = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "Freehand BSpline") 
GP.GordonProfileFP(fp, [], pts, typ) 
GP.GordonProfileVP(fp.ViewObject) 
fp.recompute() 
Gui.runCommand('Std_ToggleVisibility', 0)

Future Improvements (TODOs)

Some limitations still need attention:

  • Automatically calculate numberOfControlPoints based on curve length

  • Enable multi-curve selection to generate multiple B-splines at once

Developer Notes and Advanced Resources

Thanks to Chris G, creator of the FreeCAD Curves workbench, for providing this additional code sample that shows how B-splines can be created using GordonProfileFP:

from freecad.Curves import gordon_profile_FP as GP
sub = []

pts = [
    FreeCAD.Vector(0, 0, 0),
    FreeCAD.Vector(5, 0, 0),
    FreeCAD.Vector(10, 0, 0)
]

typ = [0, 0, 0]

fp = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "Freehand BSpline")
GP.GordonProfileFP(fp, [], pts, typ)
GP.GordonProfileVP(fp.ViewObject)
fp.recompute()

This can be adapted for snapping points to specific shapes using the sub parameter.

What’s Coming Next?

Here’s what I plan to work on next with FreeCAD macros:

  • Convert ISO Curve to Editable B-Splines (in progress)

  • Convert ISO Curves to Editable Surface (coming soon)

Final Thoughts

This macro is a foundational step toward creating a Rhino3D-style workflow inside FreeCAD, especially for users who value surface and curve modeling. It's still early days, but the potential is exciting.

Have any feedback or ideas? Drop a comment or subscribe to get updates on future macro releases.


Comments

Popular posts from this blog

Beginners FreeCAD: Exercise 5.1 & 5.2 (Reference Images)

Welcome to the total beginners course to FreeCAD 0.20. In this is a two part lesson we will practice our tracing skill in the form of a mini project. Using the below reference photos we will create a more complex part which will consist of repeating features. We will utilise the symmetry tools to ease construction in both FreeCAD sketcher and Part Design workbench. This project work will help teach the fundamentals of freeCAD allowing a understanding of the basics but delivering this information via teaching you different workflows. In this tutorial we will be tracing photos imported into FreeCAD via the image workbench https://wiki.freecadweb.org/Image_Workbench JUMP TO IMAGES Do you want to purchase the complete series along with others and keep forever?  Check out my shop https://ko-fi.com/mang0/shop The story of this tutorial The idea and first attempt at creating this tutorial was back in FreeCAD 0.18.  The physical part itself, well, I have no idea what really it is, i...

FreeCAD For Beginners: CAD Thinking Part 1

Step-by-Step CAD Thinking FreeCAD Tutorial: Modeling a Latch Part (Part 1) Learning how to turn real life objects into CAD Models. Using FreeCAD we explain at a beginner level how to break down a physical object into its primitive shapes to digitise it into a 3D model, with this episode we are looking at a multi-part assembly, modelling each piece individually. The series aims to open your eyes and mind giving you the ground skills to pick the correct profiles, geometry and workflow when it comes to modelling your parts. This is not just for FreeCAD but for all CAD packages out there. Introduction This tutorial is the first in a series guiding you through modeling a latch assembly in FreeCAD (version 0.21) using the Part Design and A2Plus workbenches. It focuses on modeling the first part (a slotted component) by selecting the top profile to create a slot and adding side arcs, emphasizing CAD thinking to break down complex shapes into primitives. The tutorial highlights model stability...

Beginner FreeCAD Tutorial 14: Reference Document for Exercise 1

This tutorial focuses on modelling a deck eye plate. These items are normally made of stainless steel with some kind of galvanised coating to stop corrosion. They are used in many industries but are most commonly found around boats, ships, sail lofts and docks where they play an important part in marine industry. Finding their use in many applications, they are often wall mounted acting as lashing points for mooring and for tying down sails or canopies. They can even be used for domestic use around the house and garden, for example to anchor ropes, cords and lines. So if your into 3D printing your finished creations, you can make use of the finished result.   Disclaimer : The strength of the part will depend on the internal structure, settings of the slicer and the material it has been printed on.  This will limit its application as failure of the part, damage to property and injury is a possibility.  These items are normally made of steel and are tested to take a...