anything

It appears you have not registered with our community. To register please click here ...

Share this topic on AskShare this topic on Del.icio.usShare this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on MagnoliaShare this topic on MySpaceShare this topic on RedditShare this topic on SlashdotShare this topic on SquidooShare this topic on StumbleUponShare this topic on TechnoratiShare this topic on TwitterShare this topic on YahooShare this topic on Google buzz

Author Topic: GIMP Defaults Script - "Mad Lib" Style  (Read 3842 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline fencepost

  • Cheif Editor
  • ********
  • Posts: 2518
  • Karma: 0
    • fence-post.deviantart.com
GIMP Defaults Script - "Mad Lib" Style
« on: February 06, 2008, 11:11:58 AM »
EDIT: Tutorial updated on March 20, 2009 to work in GIMP 2.6.

Hello, Class!

In this tutorial, I'll show you how to create a script, Mad Lib style!  As I'm sure you already know, Mad Libs is the fun game where you fill in the blanks with requested information and when you're done, you get a funny storyline.  (For those of you who have never played Mad Libs before, you can read about it here: You are not allowed to view links. Register or Login).  The results from our "Mad Lib" script won't be a funny story, but a very usable script created by you, for you. 

If the subject of scripting scares you to death, don't let it keep you from trying this tutorial.  I promise it will be painless!  There's a LOT of detail, but I've done the tutorial in such a fashion that you'll have a good time with it! There's also a money back guarantee....so what do you have to lose?  ::)

Here's how it works: Let's say that our husband and wife admin staff members, Darth_Gimp and Damascus, use the same computer with GIMP on it.  Darth has certain settings he likes to use, but every time Damascus uses GIMP, she changes the settings to her favorites (and we all know Darth, who must have his settings, does the same thing in return to her!)  These types of issues could put a significant strain on a marriage.  Well, if we could put together a simple script so that Darth could have his settings and Damascus could have her's, life would be happy in the Darth/Damascus household.  Who knew that GIMP scripting could keep a couple out of counseling?!  :P

Well, that's what this tutorial is all about.  I'll present a simple script that has several options for setting various defaults and all that you have to do is fill in the blanks.  No scripting knowledge required!  In fact, I'll walk you through the entire process.  It's very simple.

With the script in it's current format, you could do the following:

Set the foreground/background colors, the active brush, gradient, pattern & font.

Let's begin!

Step 1 - Download the Template Script

Please download the template script from here (You are not allowed to view links. Register or Login
Click Me for MyDefaults Script!
) and open it up in your favorite text editor.

Step 2 - Let's Evaluate the Script

If you were to save the current script to your GIMP scripts folder and Refresh the script, you would notice that there it shows up in the Image window under File > My Defaults.  Clicking on the My Defaults option would do absolutely nothing.  Why?  Because I've disabled all of the actual "commands" by placing them behind a semi-colon, which is the Scheme language's way of allowing the programmer to place comments in the script.  So, everything, with the exception of defining the function and registering it with the Procedural Database, is nothing but a comment.  In order to make our script run, we'll need to delete the semi-colon from the desired commands and assign the necessary values.

For example....the command to change the foreground color in our template script looks like this (notice the semi-colon before the command - I've highlighted it in red):

; (gimp-context-set-foreground '(60 134 196))

So that GIMP will actually "see" it as a command, simply delete the semi-colon as shown:

(gimp-context-set-foreground '(60 134 196))

Step 3 - Modifying the Script

Here I will show you how to modify the script to use every option I've set up.  I'll also explain what to do if you don't want to use a particular option. 

Let's play Mad Lib scripting!

In each "command", I'll bold the options that need to be changed and give you a brief description on what to change it with.

In keeping with our storyline, it is assumed that Darth and Damascus will each create their own default scripts.  However, in order for both of them to work correctly, each script has to have a unique function name registered with the Procedural Database.  In fact, for any script to run, it must have a unique name.  For those of you who are only doing one script for the time being, you can leave everything as is.



Assign a Unique Name to the Function

You can call these functions anything you want, but they need to be the same names in the define & register sections AND the register section needs to have the name in quotes! ALSO, the function names must be unique to the Procedural Database.  So, if you're unsure if a desired function name is already registered with the Procedural Database, go to Help > Procedure Browser and type in the desired name.  If it doesn't appear, you're good to go!  Otherwise, modify the name to make it unique. Place the function name in the bold area below.

(define (my-gimp-defaults)



Set the Foreground/Background Colors

Here, we're going to set our foreground/background colors to new ones.  My desired default foreground color is a pretty blue and the background color will be red, as shown in the next two commands.  (Remember to delete the semi-colon in the script so that GIMP can read it.)

(gimp-context-set-foreground '(60 134 196))
(gimp-context-set-background '(255 0 0))

Using the foreground command as an example, notice the numbers in parenthesis: 60 134 196.  The 60 represents the R-value, 134 the G-value, and 196 the B-value from the RGB color scheme.  So, to find the values for your desired color, open up the Color selector dialog by double-clicking on the foreground color swatch, pick somewhere on your desired color, and get the appropriate R G B values and place them as shown (a space needs to be in-between each value).





Set the Brush

To set the default brush, open the brush dialog window, choose the desired brush and get it's name.  I've chosen the Circle Fuzzy (17) brush. 



Since this is a name, you must surround it with quotes as shown. 

(gimp-context-set-brush "Circle Fuzzy (17)")



Set the Gradient

I'd also like the German flag smooth gradient to be my default.  Just like the brushes, get the name from the gradient dialog window.



Since this is a name, you must surround it with quotes as shown.  The command will look like so:

(gimp-context-set-gradient "German flag smooth")



Set the Pattern

Setting the pattern name is very similar to the brushes/gradients. Just open up the Pattern Dialog Window, select the desired pattern and you'll see the name of it at the top. 



Put this name exactly as shown in the Pattern Dialog Window (without the pattern dimensions - for example 45 x 45) within quotes as shown.

(gimp-context-set-pattern "3D Green")



Set the Font

I happen to like the Scriptina font.  So, I look in my font window, copy down the name shown there and type it below as shown.  If you don't have Scriptina or don't want to use it, obviously choose your desired font.



Since this is a name, you must surround it with quotes as shown.

(gimp-context-set-font "Scriptina")



Register the Script and Assign a Menu Location

Remember the Unique Name we assigned to the function above? Well, that same name needs to be added to the Register section, which is near the bottom of the script as shown (the name MUST be in quotes)

(script-fu-register "my-gimp-defaults"

The other thing they'll want to change is the Menu location.  Currently it can be found here: "<Image>/File/My Defaults"

Darth could set his up as: "<Image>/File/Darth's Defaults" and Dam's as "<Image>/File/Dam's Defaults"   That way, each of them knows where their script is located.  You change the bold information to fit your situation.

At this point, nothing else needs to be changed!  The script is ready for use.  So let's do a little test run.  Save your current script to your scripts folder, C:\Program Files\GIMP-2.X\share\gimp\2.0\scripts, add an "scm" extension to the end.  Windows users: Windows has a nasty habit of adding a "txt" extension to the end of script files when using Notepad/WordPad.  In Notepad, make sure you choose "All Files" under the Save As Type dropdown (don't use Text files) and in WordPad, make sure you use "Text Document" under the Save As Type Dropdown.  I know it's a pain/confusing, but that's the way it is. Then, refresh your scripts. 

The script should be located here: Image Window: File > My Defaults (or at the Menu location you may have specified as described previously).

Hopefully, the changes you made above will return the correct values.  If not, make sure you've made the changes correctly, resave, refresh, and try again.

That, my friends, is how we script, Mad Lib style!  Maybe try setting up different defaults for different uses.  Maybe one for large pieces or one for signatures, etc.  However, remember, if you set up more than one, you need to give it a new function/register name and menu location as described above.

I hope you enjoyed this tutorial.  If you run into any snags or want to try adding other options, let me know and I'll help you as best as I can.

Happy GIMPing!

Art
« Last Edit: May 15, 2010, 07:45:37 PM by Hi-T3k~HillBilly »
I'd rate you as an upper-middle-lower-mod with pro-novice-inter tendencies.....and a twist of lime!  Of course, my rating scale is completely objectively subjective, but ALWAYS consistently inconsistent.

Offline PhotoComiX

  • Jr. Member
  • **
  • Posts: 80
  • Karma: 0
Re: GIMP Defaults Script - "Mad Lib" Style
« Reply #1 on: February 06, 2008, 05:46:55 PM »
 :h_star: beautiful idea

Offline fencepost

  • Cheif Editor
  • ********
  • Posts: 2518
  • Karma: 0
    • fence-post.deviantart.com
Re: GIMP Defaults Script - "Mad Lib" Style
« Reply #2 on: February 06, 2008, 08:21:07 PM »
Hey, PC!  Thanks for the feedback!

I may try and restructure this thing to a more simple format.  There might be too much detail to "wade" through.  If anyone has any suggestions for improvement, I'm certainly open to hear them.

Art
I've got an idea for simplifying this considerably and will work on it over the next few days.
Well, for those of you who saw the first version of this, you may not think it's been condensed much, but it REALLY has!  I've removed all of the information relating to the creation of a new image and layer and a LOT of extra dialog to avoid boring/confusing people.  I realize that some of the details I've left out may generate questions.  But, it's a risk I'm willing to take.  ;)  Let me know if you have any questions or suggestions for improvement.  I want this to be a fun exercise.

Art
« Last Edit: February 07, 2008, 07:25:33 AM by fencepost »
I'd rate you as an upper-middle-lower-mod with pro-novice-inter tendencies.....and a twist of lime!  Of course, my rating scale is completely objectively subjective, but ALWAYS consistently inconsistent.

Offline Darth_Gimp

  • Admin
  • ********
  • Posts: 2798
  • Karma: 0
  • Reyn Til Runa!
    • lds-jedi.deviantart.com
Re: GIMP Defaults Script - "Mad Lib" Style
« Reply #3 on: February 07, 2008, 12:09:27 PM »
YAY I can have my own settings again wewp!!

Thanks for this Fence, I will be giving it a shot this weekend.
GimpDome Group: You are not allowed to view links. Register or Login
My DeviantArt: You are not allowed to view links. Register or Login

There's no worse feeling than that millisecond you're sure you are going to die after leaning your chair back a little too far.

Offline Hi-T3k~HillBilly

  • Admin
  • ********
  • Posts: 1462
  • Karma: 0
    • hitech-hillbilly.deviantart.com
    • hitek_hillbilly:imageshack
    • droz928: PhotoBucket
    • jcdillon28:twitter
    • HillBillyGFX
Re: GIMP Defaults Script - "Mad Lib" Style
« Reply #4 on: February 07, 2008, 01:31:07 PM »
Well using your template i created the script.... It works really nice!

Since i am the only one who uses my PC with Gimp I thought i would test it and see how well it worked, but i was trying to figure out why i would really need it. So it dawned on me... I could use it to reset every thing back to default quickly. I have a bad habbit of setting tool options and forgetting that i did it. Than i open gimp an hour or two later and low and behold say the bucket is set to color insted of normal.... This can get frusterating. No with your script and a little investagation I found out how to reset back to normal....

Two thumbs up Fence this is a wicked idea and works great.
You are not allowed to view links. Register or Login

You are not allowed to view links. Register or Login
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
.
Permissions beyond the scope of this license may be available by contacting H1~T3k_HillBilly

Offline Darth_Gimp

  • Admin
  • ********
  • Posts: 2798
  • Karma: 0
  • Reyn Til Runa!
    • lds-jedi.deviantart.com
Re: GIMP Defaults Script - "Mad Lib" Style
« Reply #5 on: February 07, 2008, 02:05:41 PM »
with your script and a little investagation I found out how to reset back to normal....

Mind sharing that? I could really use that as well.
GimpDome Group: You are not allowed to view links. Register or Login
My DeviantArt: You are not allowed to view links. Register or Login

There's no worse feeling than that millisecond you're sure you are going to die after leaning your chair back a little too far.

Offline fencepost

  • Cheif Editor
  • ********
  • Posts: 2518
  • Karma: 0
    • fence-post.deviantart.com
Re: GIMP Defaults Script - "Mad Lib" Style
« Reply #6 on: March 20, 2009, 09:24:22 AM »
Glad you've found it useful!  I really like it a lot as it works so fast.

As far as setting the defaults, I don't know if there's a single command for all of them (haven't done any research on that), but I do know that if you add the command:

(gimp-context-set-default-colors)

Your color swatches will be reset to the defaults of black (foreground)/white (background).  Of course, if you do this, you either need to keep the semi-colon in front of the two commands regarding changing the foreground/background colors OR delete them from the script.  No need to change them just to change them back.

But, if there are no other easy commands like that for the others, what you can do is find out what GIMP's defaults are and substitute those values into the script.  I believe the defaults are:

Gradient: FG to BG (RGB)
Pattern: Pine
Brush: Circle Fuzzy (17)

Jake will fill us in with his findings.

Posted on: February 07, 2008, 05:37:16 PM
Just thought I'd let you know that with the new interface changes in GIMP since I first created this tutorial, the script will not show up under the Xtns > My Defaults menu since that menu no longer exists.  With the menu path listed in my script, GIMP will automatically place it under Filters > My Defaults.  I'll change the tutorial later to make it up-to-date.

Art

Posted on: March 11, 2009, 04:23:54 PM
HiTech-HillBilly brought up a point earlier in this thread about returning everything back to GIMP's original default settings.  After further research, the only way to do that is going into GIMP's preferences and resetting them there, but that requires GIMP to restart before the reset takes effect.  If anyone wants to create their own script to do that, I believe the following settings are the defaults used by GIMP.  You should be able to plug these values in as described above.  Just make sure you give it a new function name and save the script with a different name (ie...  newname.scm)

Brush: Circle (11) (13X13)
Foreground color: black
Background color: white
Gradient: FG to BG (RGB)
Pattern: Pine
Palette: Default
Font: Not sure since this might be system dependent.

Let me know if this helps, if you have any questions, or have additional information.  I'll be updating this tutorial soon to cover the changes in GIMP 2.6

Art

Posted on: March 20, 2009, 11:30:23 AM
Tutorial has been modified to work using GIMP 2.6 interface changes.  Please download the new template script so that you can follow along exactly with the tutorial and remember to delete the other template script to avoid conflicts.

Art
I'd rate you as an upper-middle-lower-mod with pro-novice-inter tendencies.....and a twist of lime!  Of course, my rating scale is completely objectively subjective, but ALWAYS consistently inconsistent.