Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

fscad - A framework for programmatic CAD in Fusion 360

JesusFreke
Advocate

fscad - A framework for programmatic CAD in Fusion 360

JesusFreke
Advocate
Advocate

I started using OpenSCAD when I first got into 3D printing, and used it almost exclusively. As a software engineer by trade (and by hobby :)), I really like OpenSCAD's programmatic approach to CAD design. However, I finally got annoyed enough with a few aspects of OpenSCAD (UI sluggishness, very limited language, etc.),  that I started to look for an alternative.

 

One option I investigated was using Fusion's API to create designs programmatically. Fusion's API is great, but it does tend to be... a tiny bit verbose 🙂 I felt it was too cumbersome for the way I wanted to work.* So I decided to write a separate framework that enables the style of design that I had in mind, using Fusion's APIs in the background.

 

Coming from OpenSCAD, I developed fscad to have a similar "style" of programmatic CAD, where the basic design flow is focused around doing boolean operations of primitive geometric objects.

 

e.g.

 

from fscad import *

def my_design():
    # Create a sphere of radius 10 cm centered at the origin
    sphere = Sphere(10)

    # Create a box that is half the size of the sphere in the x direction, and the same size of the
    # sphere in the y and z directions. The minimum point of the box starts out at the origin
    box = Box(sphere.size().x/2, sphere.size().y, sphere.size().z)

    box.place(
        # place the right edge of the box (+box) at the right edge of the sphere (+sphere)
        +box == +sphere,
        # and place the center of the box (~box) at the center of the sphere (~sphere) in the y
        # and z directions
        ~box == ~sphere,
        ~box == ~sphere)

    # Subtract the box from the sphere, leaving the left side of the sphere as a hemisphere
    hemisphere = Difference(sphere, box)
    # Nothing is actually added to the Fusion 360 document until create_occurrence() is called.
    # This is typically the last thing done on the top-level component that has been built up by
    # multiple previous operations.
    # create_children=True adds the sphere and box as hidden sub-components in the Fusion 360
    # component hierarchy. This allows you to browse through the component hierarchy to see how the
    # component was built up.
    hemisphere.create_occurrence(create_children=True)

# This is the entry point for a Fusion 360 script
def run(context):
    # This is an fscad helper function to set up a new document that will be populated by this script. It will call
    # the specified function (my_design) after creating and setting up a fresh document.
    run_design(my_design, message_box_on_error=False, document_name=__name__)

 

Anyway, I've made the project available on github, if anyone is interested and wants to try it out.

 

And here's an example of a non-trivial project designed with it 🙂

 

lalboard

 

 

* This is in no way meant to be a critique of Fusion's API. I think the API is actually very well done (for the most part :)). It's just that it wasn't written for the style of programmatic CAD that I wanted to do.

 

7 Likes
Reply
1,082 Views
0 Replies
Replies (0)