Little Mafföh, big scripts!

Discussion in 'General GIMP help' started by Maffe811, Nov 22, 2010.

  1. Maffe811

    Maffe811 The forum pet Staff Member

    Joined:
    Jul 2, 2009
    Messages:
    6,814
    Likes Received:
    1
    Trophy Points:
    38
    Location:
    Norway/Norge/Norwegen
    Okay... so i... uhm, i found a script in my fx-foundry scripts that renames layers like this:

    From
    Layer backround
    Layer render
    Lay0r border
    Layah gradient mapz

    To 1a
    (0)_Layer Layer backround
    (1)_Layer Layer render
    (2)_Layer Lay0r border
    (3)_Layer Layah gradient mapz

    Or 1b
    (0)_Layer
    (1)_Layer
    (2)_Layer
    (3)_Layer

    got it ?

    --

    Okay, this is the only script i got that has the number value infront of the name!
    And in the script file it says:

    (Blahblahblahblah (layer...sth("_Layer")))

    And i changed it to:

    (Blahblahblahblah (layer...sth("_Layer (15ms) (replace) ")))

    for animation purposes

    My Q is:
    how do i change a static text like _Layer into.. uhm.. *Inputnamehere*.
    And how do i make it so i can change the *inputnamehere* in the script GUI!
     
  2. humblejohnny20

    humblejohnny20 Member

    Joined:
    Nov 17, 2010
    Messages:
    169
    Likes Received:
    0
    Trophy Points:
    16
    At the bottom of the scripts there's usually a group of variables which appear in the GUI.

    I think you also need to define them at the top

    You'd need an SF-STRING type.

    Can you upload the script or is it proprietary :p
     
  3. Maffe811

    Maffe811 The forum pet Staff Member

    Joined:
    Jul 2, 2009
    Messages:
    6,814
    Likes Received:
    1
    Trophy Points:
    38
    Location:
    Norway/Norge/Norwegen
    I have no idea what this mean, but it says you are free to change the script the way you want and to re-distribute if that whats concernin ya!

    Fx-Foundry
    DL that ^, and find "bates-layers-number.scm"
     
  4. humblejohnny20

    humblejohnny20 Member

    Joined:
    Nov 17, 2010
    Messages:
    169
    Likes Received:
    0
    Trophy Points:
    16
    Ok, I dont know if this is exactly wat u want, but i added a SF-STRING input box, and the end of the layer name will become what you enter. I learned a little bit also :p
    Took about 5 minutes. You should be able to customize it from there.


    Code:
    
    ;
    ; The GIMP -- an image manipulation program
    ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
    ;
    ; Number layers script  for GIMP 2.4
    ; Created by Daniel Bates
    ; Edited by humblejohnny20
    ;
    ; Tags: public domain, layer names
    ;
    ; Author statement:
    ;
    ; Script designed to add number notation to the layers of the current image
    ; User chooses at what number layer to begin numbering
    ; Used mainly to identify which layers to affect with the other layer options scripts
    
    ;
    ; --------------------------------------------------------------------
    ; Distributed by Gimp FX Foundry project
    ; --------------------------------------------------------------------
    ;   - Changelog -
    ;
    ; --------------------------------------------------------------------
    ;
    ; This script is released into the public domain.
    ; You may redistribute and/or modify this script or extract segments without prior consent.
    
    ; This script is distributed in the hope of being useful
    ; but without warranty, explicit or otherwise.
    ;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    
    ; Define Script
    
    (define (script-fu-number-layers theImage theDraw theLayer theLName theReplace)
    
    ; Define Variables
    
    (let*
    (
        (theNumber 0)
        (theRepeat 0)
        (theName 0)
        (theLayerRef 0)
     )
    
    
    ; Begin an undo group
    (gimp-undo-push-group-start theImage)
    
    ; Get the number of layers in an image and set to a variable
    (set! theNumber (car (gimp-image-get-layers theImage)))
    
    ; Set the repeat variable by subtracting the user input value from the total number of layers
    (set! theRepeat (- theNumber (- theLayer 1)))
    
    ; If repeat is less than 1 produce error message and exit, otherwise continue script
    (if (< theRepeat 1)
    (begin
    (set! theLayerRef (car (gimp-message-get-handler)))
    (gimp-message-set-handler 0)
    (gimp-message "Error: Input layer number exceeds total number of layers!")
    (gimp-message-set-handler theLayerRef)
    (gimp-undo-push-group-end theImage)
    )
    (begin
    
    ; If user input is higher than the number of layers in the image readjust user input to the number of layers
    (if (> theLayer theNumber)
    (set! theLayer theNumber))
    
    ; Set up variable for setting active layers and attributes
     (set! theLayerRef (cadr (gimp-image-get-layers theImage)))
    
    ; Alter theNumber for use in setting active layers and attributes
    (set! theNumber (- theNumber (- theLayer 1)))
    
    ; Begin loop and continue while repeat is higher than zero
    (while (> theRepeat 0)
    
        ; Set the layer to be editted as the active layer
        ; (set! theDraw (gimp-image-set-active-layer theImage (aref theLayerRef (- theNumber 1))))
    
        ; Get the layer's name and append a number to it
        (if (= theLName TRUE)
        (set! theName (string-append "(" (number->string theLayer) ")" "_" (car (gimp-drawable-get-name (aref theLayerRef (- theNumber 1))))))
        (set! theName (string-append "(" (number->string theLayer) ")" theReplace)))
    
        ; Assign name to the layer
        (gimp-drawable-set-name (aref theLayerRef (- theNumber 1)) theName)
    
        ; Alter variables ready for checking for next layer and applying to next layer
        (set! theLayer (+ theLayer 1))
        (set! theNumber (- theNumber 1))
        (set! theRepeat (- theRepeat 1))
    
    )
    
    ; Update visual display
    (gimp-displays-flush)
    
    ; End undo group
    (gimp-undo-push-group-end theImage)
    
    ))
    ))
    
    ; Register script
    (script-fu-register     "script-fu-number-layers"
                "<Image>/FX-Foundry/Multi-Layer Tools/Number Layers..."
                "Edits layer names to number them. Numbering starts at user's specified number. Effect is culmulative if layers maintain original names."
                "Daniel Bates"
                "Daniel Bates"
                "Dec 2007"
                "*"
                SF-IMAGE "SF-IMAGE" 0
                SF-DRAWABLE "SF-DRAWABLE" 0
                SF-ADJUSTMENT _"Start at which layer?" '(1 1 2000 1 5 0 1)
                SF-TOGGLE _"Maintain current layer names?" TRUE
                SF-STRING _"Replace Name" "MyName"
    )
    
    
    
    "theReplace" is the name of the variable, I don't know what you want to call it. The default value is "MyName".
     
  5. humblejohnny20

    humblejohnny20 Member

    Joined:
    Nov 17, 2010
    Messages:
    169
    Likes Received:
    0
    Trophy Points:
    16
    Is it working?


    [​IMG]
     
  6. Maffe811

    Maffe811 The forum pet Staff Member

    Joined:
    Jul 2, 2009
    Messages:
    6,814
    Likes Received:
    1
    Trophy Points:
    38
    Location:
    Norway/Norge/Norwegen
    my gimp froze when trying sumthin.... xD
    so im gonna try when i have the time, but we had/have lotz of tests this week!
    math, a whole day of new-norweigan (on friday) and... uhm.... i think somethin....
     

Share This Page