01-27-2023, 03:52 AM
(This post was last modified: 01-27-2023, 03:54 AM by BaconWizard17.
Edit Reason: Adding extra thoughts
)
Hi all, I've got another Python-Fu question. I'm trying to set up a script for exporting a file. As part of that, I want to create a new folder for the output if it doesn't exist. Here's the code:
Everything here is functional except for the part that creates the new folder. I don't have a function for exporting the image right now. My plan was to work on that after I got the folder creation part figured out. I tested the folderCheck function outside of GIMP in regular Python (with some expected inputs), and it worked completely fine and created the expected folder. Here's that test code for comparison, which worked flawlessly:
Does GIMP just not have permissions to create a new folder, does this function not work in GIMP, or is there something else going on here?
Edit: Something I thought of: Is creating the folder even necessary? Or will GIMP automatically create a folder if it doesn't exist for export?
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from gimpfu import*
def folderCheck(filePath, newFolder):
filePath.append(newFolder)
outFolder = "/".join(filePath)
outFolderExists = os.path.exists(outFolder)
if outFolderExists == False:
os.mkdir(outFolder)
return outFolder
def exportPNG8(image, layer):
filePath = pdb.gimp_image_get_filename(image)
filePathSplit = filePath.split("/")
fileName = filePathSplit[-1]
outFolder = folderCheck(filePathSplit[0:-1], "PNG8")
register(
"python_fu_marvelmods_export_png8",
"Exports a texture to PNG8 format.",
"Exports a texture to PNG8 format.",
"BaconWizard17",
"BaconWizard17",
"January 2023",
"Export as PNG8",
"*",
[
(PF_IMAGE, "image", "Input image", None),
(PF_DRAWABLE, 'drawable', 'Layer, mask or channel', None)
],
[],
exportPNG8,
menu='<Image>/Marvel Mods/Export Textures/By Texture Format'
)
main()
Everything here is functional except for the part that creates the new folder. I don't have a function for exporting the image right now. My plan was to work on that after I got the folder creation part figured out. I tested the folderCheck function outside of GIMP in regular Python (with some expected inputs), and it worked completely fine and created the expected folder. Here's that test code for comparison, which worked flawlessly:
Code:
import os
def folderCheck(filePath, newFolder):
filePath.append(newFolder)
outFolder = "/".join(filePath)
outFolderExists = os.path.exists(outFolder)
if outFolderExists == False:
os.mkdir(outFolder)
return outFolder
filePath = "C:/Users/ethan/Desktop/Test.xcf"
filePathSplit = filePath.split("/")
fileName = filePathSplit[-1]
outFolder = folderCheck(filePathSplit[0:-1], "PNG8")
Does GIMP just not have permissions to create a new folder, does this function not work in GIMP, or is there something else going on here?
Edit: Something I thought of: Is creating the folder even necessary? Or will GIMP automatically create a folder if it doesn't exist for export?
Modder/Skinner at MarvelMods.com using GIMP to create, edit, and export textures and previews more efficiently.
My GIMP scripts hosted on GitHub
My GIMP scripts hosted on GitHub