Ghpython file path access denied

Hi everybody. I am writing a script to export point coordinates into a .txt file. However the file direction, where I want to save the file cant be accessed, it is denied. It would be great if anybody could help my with my problem.

And another problem is that I want to have the points structured that I can build curves out of them again (later on). Would be also nice if someone knows the answer to this problem, or just the best way to structure the .txt file.

thank you all
pointExporter.gh (10.5 KB)

This seems to have slipped off the radar.

I don’t think this is a write permissions issue (though you may have seen that while attempting to write to a macOS system protected path)…

First off, I think your path needs to be somewhere you are absolutely sure that you have write permissions to. I used /Users/dan/Desktop to test this.

Next, I think you also need to make sure that the Python component’s points input needs to be set to “List Access.” I commented out some of the middle section of code and constructed a proper path that worked to write these to my desktop.

Thirdly, you need to stringify (str() or repr()) those pt.X (etc) point accessors to write them to the file.

import os
import Grasshopper as gh
import Rhino as rc

ghenv.Component.Name = "Pointexporter"
ghenv.Component.NickName = "PtExp"
ghenv.Component.Description = "exports a list of points into a .txt file"

# file = os.path.dirname(os.path.realpath(filePath))
if "." not in extension: extension = "." + extension
else: pass

#if os.path.exists(file) == False: # Test if file already exists; if it doesn't, proceed
#    file = fileName + extension # Set file name and extension
#if os.path.exists(file) == True: # If it does exists, follow the next steps
#    file_count = len([f for f in os.walk(".").next()[2] if f[-4:] == extension]) # Find #all files with the same extension
#    file = fileName + "_" + str(file_count) + extension # Add the number to the new file #name as a differentiator

path = os.path.join(filePath, fileName + extension)

# points input needs to be set to List Access
if save:
	file = open(path, "w")
	for pt in points:
		file.write(`pt.X` + ", " + `pt.Y` + ", " + `pt.Z` + "\n")
	file.close()
else:
    msg = "Set 'save' to True."
    ghenv.Component.AddRuntimeMessage(gh.Kernel.GH_RuntimeMessageLevel.Warning, msg)

Attached is a somewhat patched version of your pointExporter-v2.gh (11.7 KB) file with some minor tweaks to get it to work.

Probably too little too late, but just in case someone experiences a similar issue in GhPython in Grasshopper for Mac.