Created
July 4, 2018 13:08
-
-
Save Capo01/5595313ddf0e3c9bf892e79fac1a00b4 to your computer and use it in GitHub Desktop.
Fusion 360 equation driven curve API example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For more details see: https://capolight.wordpress.com/2018/07/02/how-to-sketch-equation-curves-in-fusion-360/ | |
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)) | |
zCoord = (2**t) | |
points.add(adsk.core.Point3D.create(xCoord,yCoord,zCoord)) | |
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())) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment