Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Spline thru Sketch Points

Anonymous

Spline thru Sketch Points

Anonymous
Not applicable

There are some scripts available which would grab a whole bunch of 3d coordinates from csv and draw splines thru those points.

As I understand there is no command in UI which would draw a spline thru points (unless you use a spline command and click every point).

Can anyone guide me how can I make a script which pt me to select a sketch with points, then create a collection object from the points inside the sketch, and draw splines thru those points?

It would also be beneficial to have the variable with sketch name being available in the code, so I could call it by name (vs pick it in the UI) uppon the execution of the script.

 

Thank you for your time and help.

0 Likes
Reply
Accepted solutions (1)
1,248 Views
7 Replies
Replies (7)

BrianEkins
Mentor
Mentor

What the API is doing is the equivalent of the command you mentioned where you click for each point on the spline.  It's just that with the API these points are provided as a list of points so you can create the list in any way you want.  It would be possible to create a script that would create a spline through every point in a sketch, but the big question is how do you determine the order of the points?  This will define how the spline passes through the points.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes

Anonymous
Not applicable

Would it be possible to connect co-linear splines only?

Something Along checking the curvature of the spline and if it is extreme, then abort further connections.

 

or can I gather the all the points from the sketch and use X coordinates to sort the order of points?

0 Likes

BrianEkins
Mentor
Mentor

You can use any method that you can conceive and have the ability to code to determine the order.  How you determine the order will mainly depend on the set of points and the result you expect, which both could be radically different from one application to another.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes

Anonymous
Not applicable

where can I start on this topic?

can you please write a snippet of getting the points from sketch into a collection and spline thru them.

Thank you

0 Likes

BrianEkins
Mentor
Mentor

Here's a small script that creates a spline through the points in the order they're returned, which you should assume is somewhat random.

 

def run(context):
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        
        skSel = ui.selectEntity('Select the point sketch', 'Sketches')
        if skSel:
            sk = adsk.fusion.Sketch.cast(skSel.entity)

            # Get all of the sketch points in the sketch.
            pnts = adsk.core.ObjectCollection.create()
            for skPnt in sk.sketchPoints:
                pnts.add(skPnt)
                
            # Create a spline through the points.
            sk.sketchCurves.sketchFittedSplines.add(pnts)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes

Anonymous
Not applicable

this actually does a decent job, as I imagined, with one exception: is there a way to knock out a origin point from this selection? in the sketch I draw 5 points, but when I launch the script it makes a spline thru 6 points, the 6th being the origin. 

0 Likes

BrianEkins
Mentor
Mentor
Accepted solution

Here it is with a slight change so that it only fits the curve through the visible points.

 

def splineThroughPoints():
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        
        skSel = ui.selectEntity('Select the point sketch', 'Sketches')
        if skSel:
            sk = adsk.fusion.Sketch.cast(skSel.entity)

            # Get all of the sketch points in the sketch.
            pnts = adsk.core.ObjectCollection.create()
            for skPnt in sk.sketchPoints:
                if skPnt.isVisible:
                    pnts.add(skPnt)
                
            # Create a spline through the points.
            sk.sketchCurves.sketchFittedSplines.add(pnts)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like