Message 1 of 6
Example of how to use sketchCurves.sketchFixedSplines.addByNurbsCurve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hopefully this will save folks in future from som hair-pulling!!! Here's some code that reproduces how the UI inserts control-point-splines.
Autodesk: You have my permission to reproduce this code as a working example in the relevant help documentation here (hint hint!):-
http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-EA5FBD51-ED6F-4D04-83B2-D72A384BC6DA
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = app.activeProduct
rootComp = design.rootComponent
sketches = rootComp.sketches
sketch = sketches.add(rootComp.xYConstructionPlane)
sketchCurves = sketch.sketchCurves
# Any arbitrary number of 4 or more points (cannot have degree-3 splines with less than 4 points)
points= [ [ 0, 0, 0 ],
[ -4, 3, 0 ],
[ -9, 3, 0 ],
[ -8, -2, 0 ],
[ -5, 2, 0 ],
[ 0, 0, 0 ] ]
# Create knots to weight all the points equally (matching how the UI control-point-spline feature works)
knots=[0,0,0,0]
for i in range(1,len(points)-3): knots.append(i)
knots=[*knots,knots[-1]+1,knots[-1]+1,knots[-1]+1,knots[-1]+1]
# Create the arrays for the nurbs
controlPoints=[]
for p in points:
point = adsk.core.Point3D.create(*p)
controlPoints.append(point)
sketch.sketchPoints.add( point ) # optional - show our control points in the sketch
# Create and insert the curve
degree=3
nurbsCurve = adsk.core.NurbsCurve3D.createNonRational(controlPoints, degree, knots, False)
sketchCurves.sketchFixedSplines.addByNurbsCurve( nurbsCurve )
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Which produces:-
p.s. If you're trying to create airfoils - my add-in is worth considering: