I need some help with writing the CSV file into the directory, where my blender file is saved. My blender file is saved in C:/MyFile and the CSV needs to be written to the same folder. C:/MyFile/file.text. If I save the blender file somewhere else, it should do the same. The script I have works well, but it will export to C:/tmp/file.txt .Thanks in advance.

# import the necessary modules we need
# in our case, blender's python API and python's os module
import bpy, os

# get the current selection
selection = bpy.context.selected_objects

# initialize a blank result variable
result = ""

# iterate through the selected objects
for sel in selection:
    # get the current object's dimensions
    dims = sel.dimensions
    # write the selected object's name and dimensions to a string
    result += "%s - %.03fm x %.03fm x %.03fm\n" % (sel.name, dims.x, dims.y, dims.z)

# get path to render output (usually /tmp\)
tempFolder = os.path.abspath (bpy.context.scene.render.filepath)
# make a filename
filename = os.path.join (tempFolder, "file.txt")
# open a file to write to
file = open(filename, "w")
# write the data to file
# close the file

Browse other questions tagged or ask your own question.