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: 

Export SketchPoint Coordinates in csv file

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
_fabschke_
1735 Views, 4 Replies

Export SketchPoint Coordinates in csv file

Hi,

 

I want to export coordinates of a point (more points in the future) to a csv-file.

I am not an experienced coder, but even with help of google and some friends I couldn't figure it out.

I tried the in python included csv module, csv.DictWriter etc. but i always get the same error.

 

OSError: [Errno 30] Read-only file system: 'coordinates.csv'

 

I tried moving the directory of the .py file to different paths, where I know i have write rights but still the error persists.

 

 #Author- 
#Description- 

import adsk.core, adsk.fusion, adsk.cam, traceback, csv 
app = adsk.core.Application.get() 
ui = app.userInterface 
pntEntity = ui.selectEntity('Select a sketch point', 'SketchPoints') 

pnt = adsk.fusion.SketchPoint.cast(pntEntity.entity) 
fields=['X-Coord','Y-Coord','Z-Coord'] 
with open(r'coordinates.csv', 'a') as coord_csv: 
writer = csv.writer(coord_csv) 
writer.writerow(fields)
writer.writerow('{0}'.format(pnt.geometry.x)) 

 

 

4 REPLIES 4
Message 2 of 5
JeromeBriot
in reply to: _fabschke_

Hello,

 

pass the full path of the CSV file to the open function.

 

The execution path is not the same as the one where your py file is stored.

 

Try this small example:

import adsk.core, adsk.fusion, adsk.cam, traceback

import os

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        ui.messageBox('{}\n{}'.format(os.getcwd(), os.path.dirname(__file__)))

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Message 3 of 5
_fabschke_
in reply to: JeromeBriot

Wow, that was easy!

Yes that worked!

Thank you very much

Message 4 of 5
karimgrase
in reply to: _fabschke_

For exporting points coordinates to a csv file, i use python add-in you can download from github,
you find it searching for username kantoku and go to repository
Fusion360-ExportSketchPointsCoordinate, or click here: https://github.com/kantoku-code/Fusion360-ExportSketchPointsCoordinate
Message 5 of 5
fivallesgarcia
in reply to: karimgrase

I just checked the code you uploaded and it is not correct. Somehow I don't get the coordinates of the construction points.

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

Post to forums  

Technology Administrators