Guest User

Epitrochoidal Disk script Fusion 360

a guest
Apr 2nd, 2024
2,392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | Source Code | 0 0
  1. import adsk.core, adsk.fusion, adsk.cam, traceback, math
  2.  
  3. def run(context):
  4.     ui = None
  5.     try:
  6.         app = adsk.core.Application.get()
  7.         ui = app.userInterface
  8.         design = app.activeProduct
  9.         # Get the root component of the active design.
  10.         rootComp = design.rootComponent
  11.         # Create a new sketch on the xy plane.
  12.         sketches = rootComp.sketches
  13.         xyPlane = rootComp.xYConstructionPlane
  14.         sketch = sketches.add(xyPlane)
  15.         points = adsk.core.ObjectCollection.create() # Create an object collection for the points.
  16.        
  17.         # Enter variables here. E.g. E = 50
  18.         R = 3.9 #Rotor Radius Centimeters
  19.         E = .075 #Input Shaft Eccentricity Centimeters
  20.         Rr = .4008 #Roller Radius Centimeters
  21.         N = 26 #Number of Rollers
  22.        
  23.         startRange = 0 # Start of range to be evaluated.
  24.         endRange = 2*math.pi # End of range to be evaluated.
  25.         splinePoints = 25*20 # Number of points that splines are generated.
  26.         # WARMING: Using more than a few hundred points may cause your system to hang.
  27.         i = 0
  28.  
  29.         while i <= splinePoints:
  30.             t = startRange + ((endRange - startRange)/splinePoints)*i
  31.             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))
  32.             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))
  33.             zCoord = (0)
  34.                  
  35.             points.add(adsk.core.Point3D.create(xCoord,yCoord,zCoord))
  36.             i = i + 1
  37.            
  38.         #Generates the spline curve
  39.         sketch.sketchCurves.sketchFittedSplines.add(points)
  40.    
  41.     # Error handeling
  42.     except:
  43.         if ui:
  44.             ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
  45.  
Advertisement
Add Comment
Please, Sign In to add comment