It is currently Mon Apr 15, 2024 8:13 am


All times are UTC - 5 hours [ DST ]


Switch to mobile style

Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Seemingly simple script question
PostPosted: Mon Jul 16, 2012 12: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.

(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
 Post subject: Re: Seemingly simple script question
PostPosted: Mon Jul 16, 2012 2:55 am  (#2) 
Offline
Script Coder
User avatar

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

(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
No matter how much you push the envelope, it'll still be stationery.


Top
 Post subject: Re: Seemingly simple script question
PostPosted: Mon Jul 16, 2012 1:58 pm  (#3) 
Offline
Script Coder
User avatar

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

_________________
Image


Top
 Post subject: Re: Seemingly simple script question
PostPosted: Tue Jul 17, 2012 2: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 3:20 pm, edited 4 times in total.

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

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

Thank you so much!

Graechan wrote:
               
(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
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Simple pastimes...

5

No new posts Where is the simple pointer

9

No new posts Attachment(s) How to create and simple Easter egg using GIMP and G'MIC

17

No new posts Attachment(s) gegl makes a simple starburst

10

No new posts Attachment(s) Photo to simple Pencil drawn

34



* Login  



Powered by phpBB3 © phpBB Group