Search code examples
functiongimpscript-fu

Script-Fu Problem with a simple function that renames the selected layer


I am writing a simple script to rename the selected layer.

Here is the code:

  (script-fu-register
    "script-fu-renaming"                          ;code name     
    "Renaming Function"                           ;name
    "This is for a question for Stack Overflow"   ;description      
    "Me"                                          ;author
    "copyright 2020, Me"                          ;copyright
    "Wednesday 8/Jul/2020"                        ;date
    ""                                            ;?
  )   

(define (script-fu-renaming)
    (gimp-item-set-name (gimp-image-get-active-layer 1) "屈")
)

But when I execute it on the Script-Fu console, through this "(script-fu-renaming 0)", I got the following error: "Error: ( : 32595) Invalid type for argument 1 to gimp-item-set-name".

So my question would be what is the code to do what I explained above without getting errors?


Solution

  • Like most GIMP functions gimp-image-get-active-layer returns a list, so you need to extract the first element using car :

    (gimp-item-set-name (car (gimp-image-get-active-layer 1)) "?")