I'm completely new to scripting, just started watching my first tutorial on this matter and the tutor in the video uses the built-in python scripting view, but has to copy and paste lines of code into the console to add the folder, that contains both the script and all associated files, and another line of code every time he updates the script outside of blender and also every time he restarts blender. I've found it more convenient to load the script into Text View, where I can even edit and update it more easily, but I can't seem to get Blender to load and save files, that are in the same folder as the script itself just by specifying their name, it only seems to work, when I specify the whole path. The instructor uses the command bpy.data.filepath to specify the filepath, but every time I try this, I get an error both in Intellij and in blender's text view, telling me, that bpy couldn't be found, in blender's python console, the command works just fine.
Any help or pointers in the right direction will be much appreciated.
' import bpy import os, sys sys.path.append(os.path.dirname(bpy.data.filepath)) ' would solve my relative path problem, but while it doesn't generate any errors, I still need to use absolute paths.
– ivan May 23 '17 at 08:42os.path.dirname(bpy.data.filepath)returns the correct path,but when I specify an external file only by it's name, the script adds the .blend file name as another folder between the path and the file, like this:D:\\filePath\\filename.blend\\external filewhile it should be:D:\\filePath\\external file.os.path.join(os.path.dirname(bpy.data.filepath), str(external_file_name))does work though.Any tips on how to get around this?
– ivan May 23 '17 at 11:14os.path.joinlooks right. If you are trying to make the path to an external file open in blender's text editor you can get it frombpy.data.texts['Text'].filepath– sambler May 24 '17 at 00:33