It is currently Sat Jun 06, 2026 5:03 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Very simple script-fu not working
PostPosted: Sun Nov 21, 2010 1:56 pm  (#1) 
Offline
GimpChat Member

Joined: Nov 21, 2010
Posts: 6
My very first script. I read through a bunch of tutorials, and can't figure out what I'm doing wrong.

I simply want to add a text layer to the current image. When I run the script, nothing appears to happen.

Eventually, I'll build this up to something that will resize an image, and put a caption in the new whitespace at the bottom. But this is my first hurdle.

Running GIMP 2.6.11 on Win 7.

Any insight would be appreciated. Thanks.

(define (script-fu-foobar inImg inDrawable)
  (gimp-context-push)
  (gimp-image-undo-group-start inImg)
 
  (let*
    (
      (theTextLayer (gimp-text-layer-new inImg "hello" "Sans" 32 PIXELS))
      (gimp-image-add-layer inImg theTextLayer 0)
    )
   
  )

  (gimp-image-undo-group-end inImg)
  (gimp-displays-flush)
  (gimp-context-pop)
)

(script-fu-register
  "script-fu-foobar"                ;func name
  "Caption"                         ;menu label
  ""                                ;description
  ""                                ;author
  ""                                ;copyright notice
  ""                                ;date created
  "RGB, RGBA"                       ;image type that the script works on
  SF-IMAGE    "Image"    0
  SF-DRAWABLE "Drawable" 0
)

(script-fu-menu-register "script-fu-foobar" "<Image>/Stuff")


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Very simple script-fu not working
PostPosted: Sun Nov 21, 2010 3:04 pm  (#2) 
Offline
Retired Staff
User avatar

Joined: May 22, 2008
Posts: 6946
Location: Somewhere in GIMP
Hi John, :welcome to Gimp Chat. Hope you enjoy yourself in here.

I moved your post to the Gimp Scripts and Plugins forum so those who do scripts/plugins will be more apt to respond to it.

O

_________________
Image
World War IV will be fought with sticks and stones. - Albert Einstein


Top
 Post subject: Re: Very simple script-fu not working
PostPosted: Sun Nov 21, 2010 3:25 pm  (#3) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
john_whorfin wrote:
      (theTextLayer (gimp-text-layer-new inImg "hello" "Sans" 32 PIXELS))

All values returned by PDB functions, when called from Script-fu, are placed within a list, even if the only thing being returned is a single value (e.g., a layerID). You need to extract that data from the list.

      (theTextLayer (car (gimp-text-layer-new inImg "hello" "Sans" 32 PIXELS)))

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Very simple script-fu not working
PostPosted: Sun Nov 21, 2010 3:44 pm  (#4) 
Offline
GimpChat Member

Joined: Nov 21, 2010
Posts: 6
Thank you saulgoode. I tried that, and still nothing.

I even renamed the menu inside my SCM file, and did a refresh to ensure I was editing the right file; and that it was being read in OK.


Top
 Post subject: Re: Very simple script-fu not working
PostPosted: Sun Nov 21, 2010 4:39 pm  (#5) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
The call to 'gimp-image-add-layer' needs to be after the bindings block of the let* statement.

  (let*
    (
      (theTextLayer (car (gimp-text-layer-new inImg "hello" "Sans" 32 PIXELS)))
      (gimp-image-add-layer inImg theTextLayer 0)
    )
   
  )


The above code is declaring a variable named 'gimp-image-add-layer'. You want to call it as a function:

  (let*
    (
      (theTextLayer (car (gimp-text-layer-new inImg "hello" "Sans" 32 PIXELS)))
    )
    (gimp-image-add-layer inImg theTextLayer 0)
  )

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Very simple script-fu not working
PostPosted: Sun Nov 21, 2010 4:45 pm  (#6) 
Offline
GimpChat Member

Joined: Nov 21, 2010
Posts: 6
That worked!

Thank you so much for that! Ya know, you stare at something so long, and just miss obvious things.


Top
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group