Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with creating an offset of a spline

1 REPLY 1
SOLVED
Reply
Message 1 of 2
mgramos
153 Views, 1 Reply

Problem with creating an offset of a spline

Please help, I am trying to add an offset to a spline to a sketch.  Here is my code:

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.
		
		d = 0.3
		k = 10
		MaxR = 5
		R = (MaxR-d)*k/(k+1)
		r = R/k
		circles = sketch.sketchCurves.sketchCircles
		circle1 = circles.addByCenterRadius(adsk.core.Point3D.create(0,0,0),r+d+R)
		circle2 = circles.addByCenterRadius(adsk.core.Point3D.create(0,0,0),R+r-d)

		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 = (R+r)*math.cos(t)-d*math.cos((R+r)*t/r)
			yCoord = (R+r)*math.sin(t)-d*math.sin((R+r)*t/r)
			zCoord = 0
                 
			points.add(adsk.core.Point3D.create(xCoord,yCoord,zCoord))
			i = i + 1
			
		#Generates the spline curve
		spl = sketch.sketchCurves.sketchFittedSplines.add(points)
		dirPoint = adsk.core.Point3D.create(0, .5, 0)
		crvs = sketch.findConnectedCurves(spl)
        offsetCurves = sketch.offset(crvs, dirPoint, 0.25)

		
	
	# Error handeling
	except:
		if ui:
			ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
1 REPLY 1
Message 2 of 2
mgramos
in reply to: mgramos

Solved.  It was a Visual Studio problem.  For some reason it is entering spaces instead of tab and that creates an error in python.  If anyone know how to solve that in VS please let me know.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report