It is currently Wed Jun 19, 2013 3:14 am


Latest GIMP Scripts & Plug-ins

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 14 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: How to delete a layer in script-fu
PostPosted: Wed Jun 01, 2011 2:22 am  (#11) 
Online
Gimp Scripts Editor
User avatar

Joined: Feb 18, 2011
Posts: 1673
Location: Australia
TA-DA

I got it


I had previously assigned "brouillard uni" as "activelayer" in the Let block all I needed was (gimp-image-remove-layer img activelayer). which did not occur to me because Frame 9 was the active layer.
Thanks for prodding me Mahvin

_________________
Image


Top
 Profile  
 

 Post subject: Re: How to delete a layer in script-fu
PostPosted: Wed Jun 01, 2011 2:30 am  (#12) 
Offline
Gimp Scripts Editor
User avatar

Joined: Jun 22, 2010
Posts: 599
Location: Here and there

Agh I got Ninja'd..... :) But here's what I was writing any way ...

The delete procedure will be expecting an id number not a string, so you need to find the id of the "Brouillard uni" layer. Here's some code I wrote as part of someone else's problem that finds a layer id based on it's name:

; routine to find the Id of a layer given the layer name
(define (kp24_find_layer_by_name image layerName)
  (let* (
           (layerList (vector->list (cadr (gimp-image-get-layers image))))    ; get the list of layer ids
           (wantedLayerId -1)
           (layerText "")
        )
       
        (for-each
          (lambda (layerId)
            (set! layerText (car (gimp-drawable-get-name layerId))) ; get a layer name
            (if (string=? layerText layerName)   ; is it the one we want?
              (set! wantedLayerId layerId)       ; it is, so save the layer id
            )           
          )
          layerList
        )
        (if (= -1 wantedLayerId)      ; didn't find it so complain
          (error (string-append "Could not find a layer with name:- " layerName))
        )
        (list wantedLayerId)
  )
)


to use it you pass it the image id and the string that is name of your layer. It returns a list containing the id of the layer:

   (set! wanted_layer_id (car (kp24_find_layer_by_name imageId "Brouillard uni")))
   (gimp-drawable-delete wanted_layer_id)


Kevin


Top
 Profile  
 
 Post subject: Re: How to delete a layer in script-fu
PostPosted: Wed Jun 01, 2011 2:34 am  (#13) 
Offline
GimpChat Member
User avatar

Joined: Oct 25, 2010
Posts: 1353
I don't use script-fu, but another possibility is to iterate the layers and delete those with a name that match "Frame*" (or whatever regexp will work in TinyScheme). Personally, I make a habit of calling my temporary work items (layers, gradients, brushes...) with a "#" so that they are easier to spot.

In python-fu you have an <Image> object, that has an array of <Layer> (unexpectedly called "layers"), ordered as in the layer stack, so the top layer is image.layers[0]. Welcome to the 21st century :)

PS: sorta ninja'd by paynejk myself :)

_________________
Image


Top
 Profile  
 
 Post subject: Re: How to delete a layer in script-fu
PostPosted: Wed Jun 01, 2011 4:25 am  (#14) 
Online
Gimp Scripts Editor
User avatar

Joined: Feb 18, 2011
Posts: 1673
Location: Australia
thank you Kevin I noted all that in case I need in future. And Offnuts its evident I don't do script-fu either :hehe

_________________
Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ]  Go to page Previous  1, 2

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: Graechan and 2 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 Gimp Chat's RSS Feed    * Subscribe to Gimp Chat's Tutorial RSS Feed


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