How to sketch equation curves in Fusion 360

The ability to sketch an equation curve is available in Autodesk’s more professional (and expensive) CAD product, Autodesk Inventor, but is missing from Fusion360’s. This tutorial details how you can get similar functionality using the Fusion 360 API.

The Fusion 360 API (Application Programming Interface) allows you to control the functionality of Fusion 360 by wiring code rather than directly through the graphical interface. This is a powerful tool which is useful for automating repetitive tasks and writing add-ins like those you will find on the Autodesk app-store.

In this tutorial we will be using the API in Fusion 360 to sketch a curve using an equation in both 2D and 3D. This is useful when you need to produce a specific, mathematically correct curve that can not be formed easily from primitive geometric shapes. For example, how would you sketch a line along the following equation

29.jpg

which when plotted over range 0 to 6.3 (2pi) (spreadsheet here) looks like the following:

33.jpg

To do so we can follow a few simple steps:

  1. Get acquainted with the basics of how to use the API by watching the following short video from the Autodesk Design Academy channel.

2. Refer to the following example python script to suit your need which can be found here.

import adsk.core, adsk.fusion, adsk.cam, traceback, math

def run(context):

ui = None

try:

app = adsk.core.Application.get()

ui = app.userInterface

design = app.activeProduct

# Get the root component of the active design.

rootComp = design.rootComponent

# Create a new sketch on the xy plane.

sketches = rootComp.sketches

xyPlane = rootComp.xYConstructionPlane

sketch = sketches.add(xyPlane)

points = adsk.core.ObjectCollection.create() # Create an object collection for the points.

# Enter variables here. E.g. E = 50

startRange = 0 # Start of range to be evaluated.

endRange = 2*math.pi # End of range to be evaluated.

splinePoints = 100 # Number of points that splines are generated.

# WARMING: Using more than a few hundred points may cause your system to hang.

i = 0

while i <= splinePoints:

t = startRange + ((endRange – startRange)/splinePoints)*i

xCoord = (math.sin(2*t))

yCoord = (math.sin(3*t))

points.add(adsk.core.Point3D.create(xCoord,yCoord,0))

i = i + 1

#Generates the spline curve

sketch.sketchCurves.sketchFittedSplines.add(points)

# Error handeling

except:

if ui:

ui.messageBox(‘Failed:\n{}’.format(traceback.format_exc()))

3. Either hit run from Anaconda (The python compiler installed by Fusion 360) or save the script and run it in Fusion 360 directly using the ‘Add-ins’ dialog box. The above script generates the following curve.

34

To extrude the shape you can select the curve and use the ‘Open/Close Spline Curve’ function to form a closed sketch.

36.jpg

Increasing the ‘splinePoints’ variable will increase the number of spline points generated and in-turn will produce a curve that more accurately fits the equation used. Below is a the same curve with 500 spline points.

35

However, using a large number of spline points (approx. >500) may cause a considerable delay in generating your sketch or may even crash Fusion 360 completely.

Also note that the API exclusively works in the units of cm for length, radians for angles (radians = degrees * pi/180) and kg for mass. If you prefer to work in different units see this section of the Fusion 360 API manual.

To extend this concept into 3D space we only need to add another coordinate Z and include that in the points object.

while i <= splinePoints:

t = startRange + ((endRange – startRange)/splinePoints)*i

xCoord = (math.sin(2*t))

yCoord = (math.sin(3*t))

zCoord = 2**t

points.add(adsk.core.Point3D.create(xCoord,yCoord,zCoord))

i = i + 1

#Generates the spline curve

sketch.sketchCurves.sketchFittedSplines.add(points)

Below is how this sketch looks when viewed face on and at an angle.

2018-07-02 21-38-53.gif

That’s it for this post. For a more in-depth understanding of the API be sure to take a look at the Fusion 360 API User manual, sample scripts and the API training series playlist on YouTube.

Big thanks to Macaba on the Odrive discord channel for showing me his cycloidal script  which I modified to use as the example in this post.

About Richard

I am a Materials Engineering working in the field of Magnetic Materials in Melbourne, Australia. This blog covers my personal interest in all things CNC.
This entry was posted in 3D Design and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s