Problem with creating an offset of a spline

mgramos
Explorer

Problem with creating an offset of a spline

mgramos
Explorer
Explorer

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()))
0 Likes
Reply
Accepted solutions (1)
256 Views
1 Reply
Reply (1)

mgramos
Explorer
Explorer
Accepted solution

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.

0 Likes