Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python-fu basics: importing and exporting files
#2
You are using keywords paramaters where you shouldn't:

Code:
Traceback (most recent call last):
 File "/home/me/Code/Gimp/NotMine/Activated/SaveLayer.py", line 27, in <module>
   menu = ("<image>/Layer")
TypeError: register() got an unexpected keyword argument 'parameters'

Also:
  • As a general rule, I find your use of register() disturbing. Most parameters are positional (see examples in linked page below).
  • There are way too many parentheses: copyright = "REC" works just as well.
  • In Python, like in all programming languages, the \ is an escape character, so where you need one as a plain character it should be doubled:  "C:\\Users\\User\\Pictures\\GIMP\\folder_1\\01.png". However:
    • In practice Windows will also accept forward slashes ("C:/Users/User/Pictures/GIMP/folder_1\01.png")
    • The right way to handle this is to
      1. Obtain the user's Pictures directory with gimp.user_directory(4) (this gives the good answer whatever the configuration and user's language on Windows, OSX  and Linux)
      2. Compose path using os.path.join()(*). For instance your path is os.path.join(gimp.user_directory(4),'GIMP','folder_1','01.png') (on all platforms).
      3. You can of course create a directory first (dir=os.path.join(gimp.user_directory(4),'GIMP','folder_1')) and then use it later in another join (os.path.join(dir,file))
To debug your Gimp python code see some hints and techniques there.

For some examples see here (especially those with export in the name)

(*) Of course you need to import os
Reply


Messages In This Thread
RE: Python-fu basics: importing and exporting files - by Ofnuts - 10-24-2022, 08:16 AM

Forum Jump: