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

Modeling Flowcharts For Basic Beginners FreeCAD v1

 Th following flowcharts are used in the Basic Beginners FreeCAD v1 course.  They consist of two flows, one for simplifying the model and one for identifying the individual features and how to model them.   The flowcharts can downloaded by clicking on them, they will then open in a new page, from there right click on the image and save as. Flowcharts can be found below.  Current flowchart version is version 1.0.0 Own my courses forever, check out my shop https://ko-fi.com/mang0/shop Own my courses forever,  check out my shop   https://ko-fi.com/mang0/shop

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...

Step-by-Step FreeCAD Tutorial: Creating a Tray with Reference Images

This tutorial helps support the original video which guides you through creating a tray in FreeCAD (version 0.21) using reference images for accurate geometry. You'll learn to import images, sketch parts with symmetry, create bevels with subtractive pipes, mirror components, and assemble the final model using the A2Plus workbench. This tutorial is designed for intermediate FreeCAD users familiar with basic sketching and navigation. Prerequisites include FreeCAD 0.21 and the A2Plus workbench installed. Reference image for the video tutorial  FreeCAD: Picture Frame / Tray Tracing, Modelling, Assembly . This image is loaded in through file > import (FreeCAD v0.21 and above) or via the image workbench (FreeCAD v0.20 and below and some earlier development versions of 0.21) Step 1: Set Up a New Document and Import Reference Image Description : Create a new FreeCAD document and import a reference image to guide your design. Instructions : Open FreeCAD 0.21 and select File > New...