Export SketchPoint Coordinates in csv file

Export SketchPoint Coordinates in csv file

_fabschke_
Participant Participant
2,803 Views
4 Replies
Message 1 of 5

Export SketchPoint Coordinates in csv file

_fabschke_
Participant
Participant

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)) 

 

 

Accepted solutions (1)
2,804 Views
4 Replies
Replies (4)
Message 2 of 5

JeromeBriot
Mentor
Mentor
Accepted solution

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()))
0 Likes
Message 3 of 5

_fabschke_
Participant
Participant

Wow, that was easy!

Yes that worked!

Thank you very much

0 Likes
Message 4 of 5

karimgrase
Explorer
Explorer
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
Observer
Observer

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

0 Likes