After a couple of suggestions which I couldn't make work, I've decided to simplify my goal and question.
My original script would generate the images properly but I was limited to having it just spit them out into w/e folder the .blend file is in.
# write image
image.filepath_raw = "//BaseRough.png"
image.file_format = 'PNG'
image.save()
I've been trying to tell it to make a new folder, direct to that, and generate the images there, but it's not working.
This line:
bpy.ops.file.directory_new(directory='//textures/', open=False, confirm=True)
Yields the error: RuntimeError: Operator bpy.ops.file.directory_new.poll() failed, context is incorrect
I'm not sure how to give it context.
I also need it to be able to read the files and assign them to the appropriate nodes, though I assume changing the load path accordingly will do that.
img = bpy.data.images.load("//BaseRough.png", check_existing=True)
to:
img = bpy.data.images.load("//textures/BaseRough.png", check_existing=True)
Update
I've been scouring the internet looking for bits of code for this, as well as any kind of explanation how the os.
system works in blender, and it led me eventually back around to this question.
I still have no idea how the window system works, but the code section on the bottom does actually work if I give it a file path to use.
Now my question is, how do I get it to use the local file's directory and add a folder to that?
os.getcwd()
'/home/monty'
# changed to:
os.getcwd()
'//'
Doesn't do anything at all. But there must be a way to define the path in a way it can see. If I can get that to work that will be good enough for now.
Someday I definitely do want to get the file window option to do the job, but clearly I'm not at that level yet.
Update
More digging has led me to this question, which inspired me to figure out this:
filepath = "//"
abs_filepath = bpy.path.abspath(filepath) # returns the absolute path
os.mkdir(str(abs_filepath+"textures"))
I'm so close I can taste it. Now I just need to write up a check for this so it's doesn't spit out FileExistsError: [Errno 17] File exists: 'textures'
self.filepath
in the execute() function. Why are you creating a text object and then running it vs just calling a function (to which you could pass the path)? $\endgroup$