As part of a larger add on, I need to save selected vertices as a text file in this format:
[
x y z;
x y z;
x y z
]
Where x y and z are the coordinates of the vertices. This text file is called later in the main function. I am new to python and I am having trouble with:
- getting permission to write this text file
- getting it to write in the aforementioned format
- calling the working directory
I have put my code down below (some of the initial imports are not used but from playing around with this). I have looked through countless platforms and similar questions and cannot find anything that helps. I made my 3 main concerns bold but please let me know if anyone has a solution to one or all of the issues, and thank you in advance!!
import bpy
import bmesh
import jdata as jd
import pathlib
import os
import pathlib
import tempfile
os.umask(0)
filefolder = #### call working directory or manually set it
selectedverts = [v for v in bpy.context.active_object.data.vertices
if v.select]
init_points = []
for v in selectedverts:
init_points.append(v.co) #saves the verticds as init_poits
os.chmod(filefolder, 0o777)
with open( filefolder,'w') as outfile:
# text = json.dumps(data, indent = 4)
outfile.write(init_points)