01-10-2024, 09:38 PM
Hi all,
I'm trying to set up a Python-Fu script that will get the file path of the current file, save the file, and then return the folder and file name of the file. For some reason, though, the os.path operations that I'm including don't appear to be working. Here's the code:
I took this code from a finished script that already works. It's a process that I use in a lot of other scripts, so I'm trying to consolidate it into one and just call this instead of copying the same code every time. But I can't get it to work on its own for whatever reason. I haven't even gotten to the point of returning the values (you can see that they're commented out). The first three pdb.gimp_message scripts work and will show something in the error console, but the last two don't show anything. It seems that the values aren't getting collected, so there's nothing to return. But I have no clue why it's not working.
I've tried using this method to debug the script, but it just crashes the Python-Fu console for some reason, so I haven't gotten any luck there.
I'm on Windows 10 and using GIMP 2.10.36. Any help would be seriously appreciated!
I'm trying to set up a Python-Fu script that will get the file path of the current file, save the file, and then return the folder and file name of the file. For some reason, though, the os.path operations that I'm including don't appear to be working. Here's the code:
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from gimpfu import*
def getPathSave(image, layer):
pdb.gimp_message("Test")
filePath = pdb.gimp_image_get_filename(image)
pdb.gimp_message("filePath = " + str(filePath))
pdb.gimp_file_save(image, layer, filePath, filePath)
pathCheck = os.path.exists(filePath) # sanity check to make sure that it's actually giving me a path
pdb.gimp_message("pathCheck = " + str(pathCheck))
folderName = os.path.dirName(filePath)
pdb.gimp_message("folderName = " + str(folderName))
fileName = os.path.basename(filePath)
pdb.gimp_message("fileName = " + str(fileName))
#return folderName, fileName
register(
"python_fu_marvelmods_basic_get_path_save",
"Saves the file and collects file path information. Returns the folder that the file is in, as well as its name (without the extension).",
"Saves the file and collects file path information. Returns the folder that the file is in, as well as its name (without the extension).",
"BaconWizard17",
"BaconWizard17",
"January 2024",
"Get File Path and Save",
"*",
[
(PF_IMAGE, "image", "Input image", None),
(PF_DRAWABLE, "drawable", "Layer, mask, or channel", None)
],
[
#(PF_STRING, "folderName", "The folder that the file is in"),
#(PF_STRING, "fileName", "The file name")
],
getPathSave,
menu='<Image>/Marvel Mods/Basic Procedures'
)
main()
I took this code from a finished script that already works. It's a process that I use in a lot of other scripts, so I'm trying to consolidate it into one and just call this instead of copying the same code every time. But I can't get it to work on its own for whatever reason. I haven't even gotten to the point of returning the values (you can see that they're commented out). The first three pdb.gimp_message scripts work and will show something in the error console, but the last two don't show anything. It seems that the values aren't getting collected, so there's nothing to return. But I have no clue why it's not working.
I've tried using this method to debug the script, but it just crashes the Python-Fu console for some reason, so I haven't gotten any luck there.
I'm on Windows 10 and using GIMP 2.10.36. Any help would be seriously appreciated!
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