Hi Sean,
The problem was that the profile you made was not perpendicular to the close path. To make the profile perpendicular to the close path, create a construction plane along the path, create the sketch on the construction plane, then create sketch circle on the sketch. I updated your script as below. It works.
#Author-seanharre@gmail.com
#Description-sweep pipe
import adsk.core, adsk.fusion, traceback
def newpt(x,y,z):
global points
point = adsk.core.Point3D.create(x,y,z)
points.add(point)
return point
def add_splines_to_plot(points):
global sketchxy
if points:
spline = sketchxy.sketchCurves.sketchFittedSplines.add(points)
all_spline.append(spline)
def main():
ui = None
try:
global app,ui,sketchxy,rootComp,points,all_spline
app = adsk.core.Application.get()
ui = app.userInterface
#design = app.activeProduct
doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
# Get the root component of the active design.
rootComp = design.rootComponent
# Create a new sketch on the xy plane.
sketchxy = rootComp.sketches.add(rootComp.xYConstructionPlane)
# Create an object collection for the points.
points = adsk.core.ObjectCollection.create()
all_spline = []
# "one face"
# fails 'CLOSED_PATH #1', works with 'CLOSED_PATH #2'
newpt(-3.0 , -2.00116 , 0.516875)
newpt(-2.9010937500000002 , -2.0006500000000003 , 0.12921875)
newpt(-2.604375 , -1.99912 , 0.0)
add_splines_to_plot(points)
points.clear()
newpt(-2.604375 , -1.99912 , 0.0)
newpt(-2.3076125000000003 , -1.99759 , 0.090481375)
newpt(-2.208575 , -1.99708 , 0.3619255)
add_splines_to_plot(points)
points.clear()
newpt(-2.208575 , -1.99708 , 0.3619255)
newpt(-2.30739375 , -1.99759 , 0.672107)
newpt(-2.6042 , -1.99912 , 0.8788005)
add_splines_to_plot(points)
points.clear()
newpt(-2.6042 , -1.99912 , 0.8788005)
newpt(-2.90105 , -2.0006500000000003 , 0.8657938749999999)
newpt(-3.0 , -2.00116 , 0.516875)
add_splines_to_plot(points)
points.clear()
# "2nd face"
# fails even with 'CLOSED_PATH #2', giving distorted splines
# newpt( -3.0 , -2.19475 , 1.1643249999999998 )
# newpt( -3.0 , -2.4164 , 1.26222 )
# newpt( -3.0 , -2.6941699999999997 , 1.2947549999999999 )
# add_splines_to_plot(points)
# points.clear()
# newpt( -3.0 , -2.6941699999999997 , 1.2947549999999999 )
# newpt( -3.0 , -2.9235425 , 1.13282 )
# newpt( -3.0 , -3.0 , 0.647305 )
# add_splines_to_plot(points)
# points.clear()
# newpt( -3.0 , -3.0 , 0.647305 )
# newpt( -3.0 , -2.875145 , 0.16182625 )
# newpt( -3.0 , -2.5005800000000002 , 0.0 )
# add_splines_to_plot(points)
# points.clear()
# newpt( -3.0 , -2.5005800000000002 , 0.0 )
# newpt( -3.0 , -2.1260149999999998 , 0.12921875 )
# newpt( -3.0 , -2.00116 , 0.516875 )
# add_splines_to_plot(points)
# points.clear()
# newpt( -3.0 , -2.00116 , 0.516875 )
# newpt( -3.0 , -2.0495574999999997 , 0.9371749999999999 )
# newpt( -3.0 , -2.19475 , 1.1643249999999998 )
# add_splines_to_plot(points)
# points.clear()
do_pipe = 1
if do_pipe == 1:
splines = adsk.core.ObjectCollection.create()
spline_prev = None
first_spline = None
for spline in all_spline:
splines.add(spline)
if not first_spline:
first_spline = spline
if spline_prev:
spline_prev.endSketchPoint.merge(spline.startSketchPoint)
pass
spline_prev = spline
if not splines:
all_spline.clear()
return
#
# CHANGING THIS COMMENT = WORKS
#
# -> CLOSED_PATH #1:
# does not work, F360 gives error
spline_prev.endSketchPoint.merge(first_spline.startSketchPoint)
# -> CLOSED_PATH #2:
# works for some reason, but takes a long time and spins CPU fan
#spline_prev.startSketchPoint.merge(first_spline.endSketchPoint)
# Create a path for the sweep path and guide rail
path = rootComp.features.createPath(splines)
#guide = rootComp.features.createPath(line)
# Create sketch for the profile to sweep
planes = rootComp.constructionPlanes
planeInput = planes.createInput()
planeInput.setByDistanceOnPath(first_spline, adsk.core.ValueInput.createByReal(0))
plane = planes.add(planeInput)
sketches = rootComp.sketches
sketch = sketches.add(plane)
center = plane.geometry.origin
center = sketch.modelToSketchSpace(center)
sketch.sketchCurves.sketchCircles.addByCenterRadius(center, 0.1)
prof = sketch.profiles[0]
# Create a sweep input
sweeps = rootComp.features.sweepFeatures
sweepInput = sweeps.createInput(prof, path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
#sweepInput.guideRail = guide
#sweepInput.profileScaling = adsk.fusion.SweepProfileScalingOptions.SweepProfileScaleOption
# Create the sweep.
sweep = sweeps.add(sweepInput)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
main()
Regards,
Jack