Python API Type help for sketchControlPointSplines.add

Python API Type help for sketchControlPointSplines.add

JWCampb
Explorer Explorer
931 Views
3 Replies
Message 1 of 4

Python API Type help for sketchControlPointSplines.add

JWCampb
Explorer
Explorer

I am trying to add a Control Point Spline based on several points, but I do not understand the correct type for the `degree` parameter. According to this doc: https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-8B8CD9F7-B4DD-44C0-A65F-90891072D18A I need to provide a `SplineDegrees` object, but I receive a TypeError with every permutation I can find, such as:

`sketch.sketchCurves.sketchControlPointSplines.add(points, adsk.fusion.SplineDegrees.SplineDegreeFive)`

0 Likes
Accepted solutions (1)
932 Views
3 Replies
Replies (3)
Message 2 of 4

kandennti
Mentor
Mentor
Accepted solution

Hi @JWCampb -San.

 

I tried this, but no error.

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion

def run(context):
    ui: core.UserInterface = None
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface
        des: fusion.Design = app.activeProduct
        root: fusion.Component = des.rootComponent

        coordinates = [
            (-5, 0, 0),
            (5, 1, 0),
            (6, 4, 0),
            (7, 6, 0),
            (2, 3, 0),
            (0, 1, 0),
        ]

        points: list[core.Point3D] = [core.Point3D.create(*c) for c in coordinates]

        skt: fusion.Sketch = root.sketches.add(
            root.xYConstructionPlane
        )

        splines: fusion.SketchControlPointSplines = skt.sketchCurves.sketchControlPointSplines
        splines.add(
            points,
            fusion.SplineDegrees.SplineDegreeFive
        )

        splines.add(
            points,
            fusion.SplineDegrees.SplineDegreeThree
        )

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


My guess is that there is something wrong with the contents of "points"?

0 Likes
Message 3 of 4

Jorge_Jaramillo
Collaborator
Collaborator

@Jorge_Jaramillo - this post is being edited to remove PII.

 

Hi @JWCampb ,

 

How did you define the points variable in your code? 

Could you share the source code of the script and the full error message?

 

The degree in a control point spline defines the number of control points it needs to calculate every segment of the spline curve.

 

Regards,

Jorge Jaramillo

 

Message 4 of 4

JWCampb
Explorer
Explorer

Thank you -- you're absolutely correct (though I'm not sure why the error seemed to point to the SplineDegrees). Turns out I had my points in an ObjectCollection as would be used by sketchFittedSplines's add method.