Python script for cycloidal disc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Folks,
After multiple attempts in trying to create a script that will sketch a cycloidal disc for me, I fear that I need to beg for assistance. I've followed the advice and method from the Autodesk Fusion 360 YouTube channel, and the "Getting Started with Python Scripting and the Fusion API" video. In this video, Michael Aubry shows how to create a sketch of the Fibonacci sequence.
I figured this method would work well for me, as I just need to draw point to point with a spline, but it is giving me an error when I try to run it. I'll the post the error below and my code below that.
I appreciate whatever help can be offered. Remember that I am simply a lowly mechanical engineer and this coding magic is fairly new to me. In other words, please speak slowly.
Error Code:
File "C:/Users/Mac/AppData/Local/Autodesk/webdeploy/production/d975d8e88973bf53c57b41882952f21f4b548a59/Api/Python/packages\adsk\fusion.py", line 26338, in add
return _fusion.SketchFittedSplines_add(self, *args)
RuntimeError: 3 : fitPoitns lenth less than 1
My Code:
import adsk.core, adsk.fusion, traceback
import math
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)
# Create an object collection for the points.
points = adsk.core.ObjectCollection.create()
####################################################
# Start my code here #
####################################################
R = 10 # Radius of the toro
E = 0.75 # Eccentricity of input shaft
Rr = 1.5 # Radius of the rollers
N = 10 # Number of rollers
l = 2*math.pi
t = (l/100)
i = 0
while i <= 100:
t = (l/100)*i
xCoord = (R*math.cos(t))-(Rr*math.cos(t+math.atan(math.sin((1-N)*t)/((R/(E*N))-math.cos((1-N)*t)))))-(E*math.cos(N*t))
yCoord = (-R*math.sin(t))+(Rr*math.sin(t+math.atan(math.sin((1-N)*t)/((R/(E*N))-math.cos((1-N)*t)))))+(E*math.sin(N*t))
points.add(adsk.core.Point3D.create(xCoord,yCoord,0))
# Create the spline.
sketch.sketchCurves.sketchFittedSplines.add(points)
i = i + 1
print(points)
print ('i = ',i)
print('t =', t)
print ('xcoord =', xCoord)
print ('ycoord =', yCoord)
Thanks Everyone,
Mac