Can the import spline from csv sample be used to import just points?

Can the import spline from csv sample be used to import just points?

MichaelAubry
Autodesk Autodesk
3,761 Views
16 Replies
Message 1 of 17

Can the import spline from csv sample be used to import just points?

MichaelAubry
Autodesk
Autodesk

Hello!

 

I've been trying unsuccessfully to figure out how to use the import just points and not have it automatically create a spline. Is there a way to accomplish this?

 

Here's the original python script:

 

 

import adsk.core, adsk.fusion, traceback

 

def run(context):

ui = None

try:

app = adsk.core.Application.get()

ui = app.userInterface

# Get all components in the active design.

product = app.activeProduct

design = product

title = 'Import Spline csv'

if not design:

ui.messageBox('No active Fusion design', title)

return

 

dlg = ui.createFileDialog()

dlg.title = 'Open CSV File'

dlg.filter = 'Comma Separated Values (*.csv);;All Files (*.*)'

if dlg.showOpen() != adsk.core.DialogResults.DialogOK :

return

 

filename = dlg.filename

f = open(filename, 'r')

points = adsk.core.ObjectCollection.create()

line = f.readline()

data = []

while line:

pntStrArr = line.split(',')

for pntStr in pntStrArr:

data.append( float(pntStr))

 

if len(data) >= 3 :

point = adsk.core.Point3D.create(data[0], data[1], data[2])

points.add(point)

line = f.readline()

data.clear()

f.close()

root = design.rootComponent;

sketch = root.sketches.add(root.xYConstructionPlane);

sketch.sketchCurves.sketchFittedSplines.add(points);

except:

if ui:

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

 

 

Thanks!

Mike

Michael Aubry
Autodesk Fusion 360 Evangelist
0 Likes
Accepted solutions (1)
3,762 Views
16 Replies
Replies (16)
Message 2 of 17

ekinsb
Alumni
Alumni
Accepted solution

This should do it.

 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface

        # Get all components in the active design.
        product = app.activeProduct
        design = product
        title = 'Import Spline csv'

        if not design:
            ui.messageBox('No active Fusion design', title)
            return
 
        dlg = ui.createFileDialog()
        dlg.title = 'Open CSV File'
        dlg.filter = 'Comma Separated Values (*.csv);;All Files (*.*)'
        if dlg.showOpen() != adsk.core.DialogResults.DialogOK :
            return

        root = design.rootComponent;
        sketch = root.sketches.add(root.xYConstructionPlane)
        sketch.name = 'CSV Points'
            
        filename = dlg.filename
        f = open(filename, 'r')
        line = f.readline()
        data = []
        while line:
            pntStrArr = line.split(',')
            for pntStr in pntStrArr:
                data.append(float(pntStr))
         
            if len(data) >= 3 :
                point = adsk.core.Point3D.create(data[0], data[1], data[2])
            data.clear()

            sketch.sketchPoints.add(point)
            line = f.readline()

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

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 17

MichaelAubry
Autodesk
Autodesk

That's it!  Thanks a lot Brian!  No way I would have got that on my own.  Thanks so much for your help.

Michael Aubry
Autodesk Fusion 360 Evangelist
0 Likes
Message 4 of 17

hanskellner
Autodesk
Autodesk

This is a little late, but here's a variation of the CSV import code that I created that allows creating of just points, lines, or splines:

 

https://github.com/hanskellner/Fusion360ImportCSVPoints

 

It also supports multiple line/spline creation by inserting a blank line between groups of points within the CSV file.

 

I created it for another app I'm working on.



Hans Kellner
Senior Manager, Principal Engineer
Message 5 of 17

mart.hough
Contributor
Contributor

This modified plugin with the option for lines or splines is EXACTLY what I needed! Thanks!

 

0 Likes
Message 6 of 17

hanskellner
Autodesk
Autodesk

Please let me know if you run into any issues.  I haven't touched the code for a while now and hope it still works.



Hans Kellner
Senior Manager, Principal Engineer
0 Likes
Message 7 of 17

adamonline45
Participant
Participant

hanskellner, that's exactly what I needed, too! Great timing, and great solution 😄

0 Likes
Message 8 of 17

Anonymous
Not applicable

This is what the standard fusion function should be!   Units, points, lines, and splines.  PERFECT, Thank you! 

Message 9 of 17

Anonymous
Not applicable

Hi guys, I am really late to this but I am hoping if you could help me here. I have followed the instructions and copied the files to the new script folder. Looks like currently Fusion360 only recognizes Python and C++ codes whereas the sources files on github are javascripts. What am I missing here? 

0 Likes
Message 10 of 17

hanskellner
Autodesk
Autodesk

Hi @Anonymous -

 

Yes, if you're speaking about my Fusion360ImportCSVPoints script, the current version posted is no longer supported.  But I am finishing up a new version and hope to have it posted in a day.

 



Hans Kellner
Senior Manager, Principal Engineer
Message 11 of 17

Anonymous
Not applicable

Great! Thanks!

0 Likes
Message 12 of 17

hanskellner
Autodesk
Autodesk

I have posted a new version of Import CVS Points on Github.  Please download and install this version.  Also, be sure to read the README for details of this version and the updates.

 

Thanks

 

https://github.com/hanskellner/Fusion360ImportCSVPoints



Hans Kellner
Senior Manager, Principal Engineer
0 Likes
Message 13 of 17

Anonymous
Not applicable

I'm having trouble with the new script and units.   No matter what units I select, it imports as if the CSV is in cm. 

0 Likes
Message 14 of 17

hanskellner
Autodesk
Autodesk

Hi @Anonymous -

 

Sorry it's not working.  Ok, I found the issue.  It wasn't setting (internally) the user's default unit type.  The UI would show it correctly but it wasn't using it.

 

I've updated the code on the Github site.

 

Thanks for reporting this.

 

Thanks



Hans Kellner
Senior Manager, Principal Engineer
Message 15 of 17

Anonymous
Not applicable

No worries,  I could just be using it wrong.   its been a couple of months since I used the previous version, so maybe I was having python convert my csv to cm before importing it into fusion.  

 

I have been working with python to create the CSV points and have been working exclusively with units of feet.  So I just changed lines 51 and 52 in the python file to 'ft' instead of 'cm' and it works for my purposes.  

 

0 Likes
Message 16 of 17

hanskellner
Autodesk
Autodesk
You're using it the right way. I just goofed but now it's fixed. Your mod to the source code is also a quick fix for your specific use case.


Hans Kellner
Senior Manager, Principal Engineer
0 Likes
Message 17 of 17

haik.vasil.3
Participant
Participant

@hanskellner Thank you so much for the plug-in!  That is really great.

I am looking to extrude pipes through those lines, I have seen there is a script for making pipes, but I am so confused with the code. I will much appreciate it if anyone can help.

0 Likes