Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Fu - mkdir not working
#5
(01-27-2023, 07:50 AM)gasMask Wrote: Hi,
I'm not a Linux user, but here's an article I found on accessing the C Drive on a Linux system.

I use Windows, not Linux

(01-27-2023, 09:17 AM)Kevin Wrote: At a guess I'd suggest the thing that's breaking is this line:
filePathSplit = filePath.split("/")

Because pdb.gimp_image_get_filename(image) is going to return a filepath in Windows format because you're runing GIMP on Windows. i.e.

C:\Users\ethan\Desktop\Test.xcf

You should probably use os.path.dirname(path) to get the directory name: https://docs.python.org/2/library/os.path.html

This generally makes sense. However, when I tested it outside of GIMP in regular Python, it gave me an error when I used the backslash but worked correctly when I used a forward slash, so that's why I coded it that way. Any idea why that might be the case? I'll try using the os function instead though.

(01-27-2023, 10:06 AM)Ofnuts Wrote: Also, instead of hard-coding the desktop directory name/location, you can get it as the results of gimp.user_directory(0)

I only hardcoded the path when I was testing the code in Python outside of GIMP (to make sure that the non-GIMP syntax worked correctly). In the full GIMP script, I'm using pdb.gimp_image_get_filename(image) to get the file path of the saved file and then manipulating that path to get the output directory.

For the sake of documentation, here's the script that I used that now works:

Code:
def folderCheck(filePath, newFolder):
   outFolder = os.path.join(filePath, newFolder)
   outFolderExists = os.path.exists(outFolder)
   if outFolderExists == False:
       os.mkdir(outFolder)
   return outFolder

def exportPNG8(image, layer):
   filePath = pdb.gimp_image_get_filename(image)
   dirname = os.path.dirname(filePath)
   fileName = os.path.basename(filePath)
   outFolder = folderCheck(dirname, "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()
Modder/Skinner at MarvelMods.com using GIMP to create, edit, and export textures and previews more efficiently.

My GIMP scripts hosted on GitHub
Reply


Messages In This Thread
Python Fu - mkdir not working - by BaconWizard17 - 01-27-2023, 03:52 AM
RE: Python Fu - mkdir not working - by gasMask - 01-27-2023, 07:50 AM
RE: Python Fu - mkdir not working - by Kevin - 01-27-2023, 09:17 AM
RE: Python Fu - mkdir not working - by Ofnuts - 01-27-2023, 10:06 AM
RE: Python Fu - mkdir not working - by BaconWizard17 - 01-30-2023, 04:06 PM
RE: Python Fu - mkdir not working - by Kevin - 01-31-2023, 10:12 AM

Forum Jump: