It is currently Sat May 25, 2013 1:30 am


Latest GIMP Scripts & Plug-ins

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Seemingly simple script question
PostPosted: Mon Jul 16, 2012 1:00 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Jul 14, 2012
Posts: 20
Script-fu

I'm writing a script that works on an open image. So I'm starting with a layer that I don't have an id for. I want to change the name of that layer so I have a set variable that I can work with through out the script. Also, if I ever merge visible, I would like to be able to name that new layer.

I sorry if this is so simple. I truly have looked around forums and read other peoples scripts but I can't work it out. Ideally, I would like to be able to combine "(gimp-image-get-active-layer image)" and "(gimp-item-set-name item name)" in some fashion to change the layer name. That way I know I can change the layer name at any time.

I know this is probably not the proper way. I'd guess I could get a little greedy here and ask for both solutions. i.e. working out how to use get-active/set-name and maybe if someone is willing to explain the proper way of changing the layer name of a newly opened image.

I do appreciate any help.

Thanks.

I've included the code (children's book : )) so you can better understand my inquiry.

Code:
(define (script-fu-pd image drawable)

       (gimp-context-push) 
       (gimp-image-undo-group-start image)
       
          (gimp-image-merge-visible-layers image CLIP-TO-IMAGE)
          (set! drawable (car (gimp-image-get-active-drawable image)))
          (gimp-image-convert-grayscale image)
          (gimp-context-set-foreground '(0 0 0))
          (gimp-context-set-background '(255 255 255))

           ;this is the point I decided I needed to have the opened image layer renamed
            so that I can work with it using the presets in the Procedure Browser.

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

(script-fu-register "script-fu-pd"
            "<Image>/Filters/PD grayscale Threshold"
            "Inprogress"
            "PD"   
            "PD"   
            "July 2012"
            "RGB*"           
            SF-IMAGE "image" 0
            SF-DRAWABLE "drawable" 0
           
)


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Profile  
 

 Post subject: Re: Seemingly simple script question
PostPosted: Mon Jul 16, 2012 3:55 am  (#2) 
Offline
Gimp Scripts Editor
User avatar

Joined: Feb 18, 2011
Posts: 1571
Location: Australia
Maybe you could start your script like this so you know the open layer is called image-layer and you know its dimensions

Code:
(define (script-fu-image image drawable
                               )
                      

(let* (
            (image-layer (car (gimp-image-get-active-layer image)))
         (width (car (gimp-image-width image)))
         (height (car (gimp-image-height image)))
         
        )
   
   
   (gimp-context-push)
    (gimp-image-undo-group-start image)
   (gimp-context-set-foreground '(0 0 0))
   (gimp-context-set-background '(255 255 255))

don't forget to close the (let* statement where you closed your define statement

_________________
Image


Top
 Profile  
 
 Post subject: Re: Seemingly simple script question
PostPosted: Mon Jul 16, 2012 2:58 pm  (#3) 
Offline
GimpChat Member
User avatar

Joined: Oct 25, 2010
Posts: 1305
Normally, if the script is properly registered, the "drawable" parameter is the active layer when the script is called...

_________________
Image


Top
 Profile  
 
 Post subject: Re: Seemingly simple script question
PostPosted: Tue Jul 17, 2012 3:26 pm  (#4) 
Offline
GimpChat Member
User avatar

Joined: Jul 14, 2012
Posts: 20
To ofnuts,

ofnuts wrote:
Normally, if the script is properly registered, the "drawable" parameter is the active layer when the script is called...


Thank you for your post. I'll recall your info when I'm writing scripts.

I guess why I needed to name the image layer is because some procedures ask for an "item" name. I read some posts/scripts and I saw people were using complicated measures to obtain the layer id, but I'm just a white belt in the Script-Fu, I need sometime practice before I can apply the more intricate scripting.

Thanks again.


Last edited by Phoenix999 on Tue Jul 17, 2012 4:20 pm, edited 4 times in total.

Top
 Profile  
 
 Post subject: Re: Seemingly simple script question
PostPosted: Tue Jul 17, 2012 3:28 pm  (#5) 
Offline
GimpChat Member
User avatar

Joined: Jul 14, 2012
Posts: 20
To Graechan,

Thank you so much!

Graechan wrote:
Code:
               
(let* (
            (image-layer (car (gimp-image-get-active-layer image)))
         (width (car (gimp-image-width image)))
         (height (car (gimp-image-height image)))
         
        )
   
)
   



Worked perfectly. Also, taught me I can be a bit more creative in the let* definitions.

Thank you!!

P.S.

Noticed your post tally was a little ironic to me considering my user name.

Image

The image isn't showing up for me. Maybe it will for you. If not, there is a link to it below.

Link to image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: Rod, saulgoode and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

* Login   * Subscribe to RSS Feed


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group