8.8 Fusion360 API
This guide will help you get started with the Fusion 360 API and develop custom scripts for automating CAD tasks.
Getting Started
Installing Fusion 360
- Download Fusion 360
- Visit Autodesk Fusion 360 download page
- Click “Download free trial”
- Get a Student License
- During registration, use your university email address
- This gives you free access to Fusion 360 for educational purposes
- The student license is valid for 1 year and can be renewed
- Visit Autodesk Education Community for more information
- Complete Installation
- Run the installer and follow the prompts
- Sign in with your Autodesk account
- Verify your educational status if prompted
Setting Up Your Development Environment
Fusion 360 scripts are written in Python. For efficient development, we’ll use Visual Studio Code alongside Fusion 360.
- Install VS Code from https://code.visualstudio.com/
- Install Python extension in VS Code for syntax highlighting and IntelliSense
Your First Script: Hello World
Let’s create a simple script that displays a message in Fusion 360.
Step 1: Create the Script File
- In Fusion 360, go to Utilities → ADD-INS → Scripts and Add-Ins
- Click the + button on the top → Create script or Add-In
- Leave the default Script
- Name it
HelloWorld - Leave the default programming language: Python
- This creates a folder in your scripts directory (typically
~/Autodesk/Autodesk Fusion 360/API/Scripts/)
Step 2: Edit in VS Code
The HelloWorld script will appear in the list.
Right-click and choose Edit in code editor to open the project in vs code.
You will see this code in the HelloWorld.py:
"""This file acts as the main module for this script."""
import traceback
import adsk.core
import adsk.fusion
# import adsk.cam
# Initialize the global variables for the Application and UserInterface objects.
app = adsk.core.Application.get()
ui = app.userInterface
def run(_context: str):
"""This function is called by Fusion when the script is run."""
try:
# Your code goes here.
ui.messageBox(f'"{app.activeDocument.name}" is the active Document.')
except: #pylint:disable=bare-except
# Write the error message to the TEXT COMMANDS window.
app.log(f'Failed:\n{traceback.format_exc()}')You cannot run the python file from VS-Code! It needs to be run from Fusion 360 as a script or add-in.
Step 3: Run the Script
- In Fusion 360, open Tools → ADD-INS → Scripts and Add-Ins
- Under “My Scripts”, select
HelloWorld - Click Run
- You should see a message box with “Untitled is the active Document.”
Workflow: VS Code + Fusion 360
The typical development workflow is:
- Edit in VS Code: Write/modify your Python script
- Save the file (Ctrl+S)
- Run/Reload in Fusion 360: Open the scripts and add-ins menu (Shift+S)
- For scripts: Click Run in the Scripts dialog
- For add-ins: Click Stop, then Run again to reload changes
- Test the functionality in Fusion 360
- Debug if needed (see Debugging section below)
- Iterate: Return to step 1
Tips: - Keep both VS Code and Fusion 360 open side-by-side - Use VS Code’s Python extension for autocomplete and error checking - Comment your code thoroughly for future reference
Reference Materials
Official Documentation
- Fusion 360 API Reference: Complete API documentation
- Python Documentation: Fusion-specific Python guide
Key API Namespaces
adsk.core: Core application functionality (UI, events, geometry)adsk.fusion: Fusion-specific features (bodies, components, features)adsk.cam: CAM-related functionality
Additional Tutorials
Example: Sequential Bridges for 3D Printing
This example is based on Fusion360GenerateSequentialBridges.
What are Sequential Bridges?
When 3D printing with FDM printers, overhanging features need support. Sequential bridges create stepped extrusions that allow the printer to build bridges progressively, layer by layer, without traditional support structures.


The Code
#Author-Your Name
#Description-Generate sequential bridges for 3D printing
import adsk.core, adsk.fusion, traceback
# Configuration: Define extrusion amounts for each bridge layer
# Adjust these values based on your layer height (e.g., 0.2mm)
extrusionAmounts = ["-0.5 mm", "-0.25 mm"]
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = adsk.fusion.Design.cast(app.activeProduct)
if not design:
ui.messageBox('No active Fusion design', 'Error')
return
# Get the root component
rootComp = design.rootComponent
# Prompt user to select faces
selection = ui.selectEntity('Select faces for bridging', 'Faces')
if not selection:
return
selectedFace = adsk.fusion.BRepFace.cast(selection.entity)
# Create extrusions for each bridge level
extrudes = rootComp.features.extrudeFeatures
for i, amount in enumerate(extrusionAmounts):
# Create a collection for the face
faces = adsk.core.ObjectCollection.create()
faces.add(selectedFace)
# Create extrude input
extrudeInput = extrudes.createInput(
faces,
adsk.fusion.FeatureOperations.NewBodyFeatureOperation
)
# Define distance
distance = adsk.core.ValueInput.createByString(amount)
extrudeInput.setDistanceExtent(False, distance)
# Create the extrusion
extrude = extrudes.add(extrudeInput)
# Update the selected face to the new surface for next iteration
if i < len(extrusionAmounts) - 1:
newBody = extrude.bodies.item(0)
selectedFace = newBody.faces.item(0)
ui.messageBox('Sequential bridges created successfully!')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))How It Works
- User selects a face that needs bridging
- Loop through extrusion amounts: Each iteration creates a stepped layer
- Create extrusion: Uses the
extrudeFeaturesAPI - Update face reference: The new surface becomes the base for the next layer
Customization
Modify extrusionAmounts based on your printer’s layer height and bridge requirements:
# For 0.2mm layer height
extrusionAmounts = ["-0.6 mm", "-0.4 mm", "-0.2 mm"] # 3 steps
# For 0.15mm layer height
extrusionAmounts = ["-0.45 mm", "-0.30 mm", "-0.15 mm"]Project Preparation: Shampoo Bottle Level Lines
For your project, you’ll need to create level lines on a non-trivial shaped bottle that correspond to specific volumes (100ml, 200ml, etc.).
Key Challenge
Correlate volume with height: Since the bottle shape is non-uniform, equal height intervals don’t correspond to equal volume intervals.
Required API Functions
Calculating Volume
Use the physicalProperties to get volume:
import adsk.core, adsk.fusion
def get_body_volume(body):
"""Get the volume of a body in cm³"""
app = adsk.core.Application.get()
design = adsk.fusion.Design.cast(app.activeProduct)
# Get physical properties
physicalProps = body.physicalProperties
# Volume is in cm³
volume_cm3 = physicalProps.volume
# Convert to ml (1 cm³ = 1 ml)
volume_ml = volume_cm3
return volume_ml
# Example usage:
# ui = app.userInterface
# selection = ui.selectEntity('Select bottle body', 'Bodies')
# body = adsk.fusion.BRepBody.cast(selection.entity)
# volume = get_body_volume(body)
# ui.messageBox(f'Volume: {volume:.2f} ml')API Reference: PhysicalProperties.volume
Splitting Bodies with Planes
To find the height for a specific volume, you’ll need to create cutting planes:
def create_construction_plane_at_height(rootComp, height_cm):
"""Create a construction plane at specified height from XY plane"""
planes = rootComp.constructionPlanes
planeInput = planes.createInput()
# Offset from XY plane
offsetValue = adsk.core.ValueInput.createByReal(height_cm)
planeInput.setByOffset(
rootComp.xYConstructionPlane,
offsetValue
)
plane = planes.add(planeInput)
return plane
def split_body_with_plane(rootComp, body, plane):
"""Split a body using a construction plane"""
splitFaces = adsk.core.ObjectCollection.create()
splitFaces.add(plane)
splitFeatures = rootComp.features.splitBodyFeatures
splitInput = splitFeatures.createInput(
body,
splitFaces,
True # True = split along both sides
)
splitFeature = splitFeatures.add(splitInput)
return splitFeatureAPI References: - ConstructionPlanes - SplitBodyFeature
Finding correct height given a volume
This is where you need to create your own solution.
Creating Sketches on Surfaces
Once you have the correct height, create a sketch for the level line:
def create_level_line_at_height(rootComp, body, height_cm, volume_ml):
"""Create a sketch line at the specified height on the body surface"""
# Create construction plane at height
plane = create_construction_plane_at_height(rootComp, height_cm)
# Create sketch on the plane
sketches = rootComp.sketches
sketch = sketches.add(plane)
sketch.name = f"Level_{volume_ml}ml"
# Create intersection curve with body
# This projects the plane intersection onto a sketch
curves = sketch.intersectWithSketchPlane(body)
return sketchAPI Reference: Sketch.intersectWithSketchPlane
Project Tips
- Start simple: Test with a cylinder first where volume/height relationship is known
- Validate volumes: After creating level lines, verify by measuring the split volumes
- Consider bottle orientation: Make sure Z-axis is vertical (height direction)
- Handle complex intersections: Some bottles may have multiple intersection curves at one height
Debugging Your Scripts
Debugging Fusion 360 scripts can be challenging since they run inside Fusion. Here are strategies:
Text Commands Window
Use Fusion’s Text Commands for output:
# Show the Text Commands window
app = adsk.core.Application.get()
ui = app.userInterface
# Write debug messages
ui.palettes.itemById('TextCommands').writeText('Debug: Variable value = ' + str(myVar))To open Text Commands: Tools → Text Commands (or Ctrl+Shift+P)
Message Boxes for Checkpoints
ui.messageBox(f'Checkpoint: volume = {volume}, height = {height}')Caution: Don’t overuse in loops - it will require clicking OK many times!
Try-Except Blocks with Traceback
Always wrap your code:
import traceback
try:
# Your code here
risky_operation()
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))This shows the exact line number and error type.
Logging to File
For complex debugging, write to a log file:
import os
from datetime import datetime
def log_debug(message):
"""Write debug message to log file"""
log_path = os.path.join(
os.path.expanduser('~'),
'fusion360_debug.log'
)
with open(log_path, 'a') as f:
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
f.write(f'[{timestamp}] {message}\n')
# Usage:
log_debug(f'Volume calculated: {volume}')
log_debug(f'Height found: {height}')Check the log file at ~/fusion360_debug.log
Incremental Development
- Build in small steps: Test each function individually
- Use simple test cases: Start with basic shapes (cube, cylinder)
- Verify intermediate results: Check values at each stage
- Comment liberally: Future you will thank present you
Common Errors and Solutions
Error: AttributeError: 'NoneType' object has no attribute 'X' - Cause: Object not found or invalid selection - Fix: Always check if objects exist before using them
selection = ui.selectEntity('Select body', 'Bodies')
if not selection:
ui.messageBox('No selection made')
returnError: RuntimeError: 2 : InternalValidationError : offset - Cause: Invalid parameter value (e.g., negative extrusion where not allowed) - Fix: Validate inputs and use ValueInput.createByReal() for numeric values
Error: Script runs once but fails on subsequent runs - Cause: Objects/handlers not cleaned up properly - Fix: Implement proper stop() function to remove UI elements and clear handlers
Summary
You now have:
- Setup instructions for Fusion 360 with student license
- A working Hello World example with toolbar button
- Understanding of the VS Code + Fusion workflow
- A practical Sequential Bridges example
- API functions for starting the shampoo bottle project
- Debugging strategies
Next Steps:
- Install Fusion 360 and VS Code
- Run the Hello World examples
- Study the Sequential Bridges code
- Start experimenting with volume calculations on simple shapes
- Build up to your shampoo bottle project
Remember: The Fusion 360 API has a learning curve, but with practice and the debugging techniques above, you’ll be automating complex CAD tasks in no time!