- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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()))
Solved! Go to Solution.