Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
MichaelAubry
2473 Views, 16 Replies

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

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
16 REPLIES 16
Message 2 of 17
ekinsb
in reply to: MichaelAubry

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
in reply to: ekinsb

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
Message 4 of 17
hanskellner
in reply to: MichaelAubry

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
in reply to: hanskellner

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

 

Message 6 of 17
hanskellner
in reply to: mart.hough

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
Message 7 of 17
adamonline45
in reply to: hanskellner

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

Message 8 of 17

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

Message 9 of 17
oa.ghani
in reply to: MichaelAubry

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? 

Message 10 of 17
hanskellner
in reply to: oa.ghani

Hi @oa.ghani -

 

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
oa.ghani
in reply to: hanskellner

Great! Thanks!

Message 12 of 17
hanskellner
in reply to: MichaelAubry

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
Message 13 of 17

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. 

Message 14 of 17

Hi @adam.blackP2Q5Y -

 

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

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.  

 

Message 16 of 17

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
Message 17 of 17
haik.vasil.3
in reply to: MichaelAubry

@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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report