RSS/Atom feed Twitter
Site is read-only, email is disabled

Script Help - Basic Macro

This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

5 of 5 messages available
Toggle history

Please log in to manage your subscriptions.

Script Help - Basic Macro adreasler 06 Feb 17:07
  Script Help - Basic Macro programmer_ceds 07 Feb 10:29
   Script Help - Basic Macro adreasler 07 Feb 13:28
    Script Help - Basic Macro adreasler 07 Feb 20:42
     Script Help - Basic Macro programmer_ceds 08 Feb 13:59
2017-02-06 17:07:52 UTC (about 8 years ago)
postings
3

Script Help - Basic Macro

I am looking to find some way to automate the following steps:

1) Duplicate the active layer, shifting focus to the duplicate (the standard effect when selecting Layer>Duplicate layer) 2) Rotate the new active layer 180 degrees (Layer>Transform>Rotate 180) 3) Move the new active layer up 200 pixels 4) Merge the new active layer with the original active layer (Layer>Merge Down)

Since this is just using existing functions within GIMP, it seems like this should be a simple script to make, however, when testing out the functions I think I need in the interactive consoles (I've tried this with both the python console and the script-fu console) All I get are errors, the functions seem to want the NAME of the layer being manipulated, even the function to GET the layer name.

I've worked with script files both in Microsoft environments and in *nix, I just need to figure out how to make this work in a GIMP environment. All of the script tutorials I've seen for GIMP seem to be either designed around automated script-writing software ("First write the pseudocode like this, then run it through this program which you can no longer find at the other end of this broken link") or they seem to be talking about a higher level programming language, writing what looks like mangled C code for 'hello world' programs.

Any help that can be provided would be greatly and humbly appreciated.

2017-02-07 10:29:56 UTC (about 8 years ago)
postings
121

Script Help - Basic Macro

You could try using the following function calls:

gimp-get-active-layer gimp-layer-copy (returns the ID of the new layer) gimp-set-active-layer (not sure if you will need this) whatever functions you need to make the required changes gimp-image-merge-down

To get started I would use the browse function in the console to get details of the functions and their associated parameters (you can type part of what you are looking for in the search box - for instance try just typing layer and see what you get) but I would advise typing the script into a .scm (or .py) file rather than having to keep entering data into the console - that saves time and typing.

Once you have made an edit to a .scm file you either have to restart GIMP to use the new version of the file or use "Filters/Script Fu/Refresh Scripts"

The error messages can be a little cryptic but using gimp-message can help to track down problems.

Look at the existing scripts in (on my PC) C:\Program Files\GIMP 2\share\gimp\2.0\scripts - search these files (or on the net) for the functions you want to use. Possibly use one of the files as the basis for your own script.

I am looking to find some way to automate the following steps:

1) Duplicate the active layer, shifting focus to the duplicate (the standard effect when selecting Layer>Duplicate layer) 2) Rotate the new active layer 180 degrees (Layer>Transform>Rotate 180)
3) Move the new active layer up 200 pixels 4) Merge the new active layer with the original active layer (Layer>Merge Down)

Since this is just using existing functions within GIMP, it seems like this should be a simple script to make, however, when testing out the functions I think I need in the interactive consoles (I've tried this with both the python console and the script-fu console) All I get are errors, the functions seem to want the NAME of the layer being manipulated, even the function to GET the layer name.

I've worked with script files both in Microsoft environments and in *nix, I just need to figure out how to make this work in a GIMP environment. All of the script tutorials I've seen for GIMP seem to be either designed around automated script-writing software ("First write the pseudocode like this, then run it through this program which you can no longer find at the other end of this broken link") or they seem to be talking about a higher level programming language, writing what looks like mangled C code for 'hello world' programs.

Any help that can be provided would be greatly and humbly appreciated.

2017-02-07 13:28:41 UTC (about 8 years ago)
postings
3

Script Help - Basic Macro

You could try using the following function calls:

gimp-get-active-layer gimp-layer-copy (returns the ID of the new layer) gimp-set-active-layer (not sure if you will need this) whatever functions you need to make the required changes

I was only using the console to work out what commands I needed; typing the commands manually into the console each time would be even slower than doing everything manually by mouse-clicking the menu items.

Thank you so much for your assistance.

gimp-image-merge-down

To get started I would use the browse function in the console to get details of the functions and their associated parameters (you can type part of what you are looking for in the search box - for instance try just typing layer and see what you get) but I would advise typing the script into a .scm (or .py) file rather than having to keep entering data into the console - that saves time and typing.

Once you have made an edit to a .scm file you either have to restart GIMP to use the new version of the file or use "Filters/Script Fu/Refresh Scripts"

The error messages can be a little cryptic but using gimp-message can help to track down problems.

Look at the existing scripts in (on my PC) C:\Program Files\GIMP 2\share\gimp\2.0\scripts - search these files (or on the net) for the functions you want to use. Possibly use one of the files as the basis for your own script.

2017-02-07 20:42:37 UTC (about 8 years ago)
postings
3

Script Help - Basic Macro

It took longer than I expected, different sample scripts take different approaches, and it's hard to week out what is and isn't important, but I finally got it worked out.

It's a really limited-purpose script, But I was just looking for a way to speed up the file tab preparation after getting the titles typed up.

Anyway, here's the hot mess of code, for the critique and amusement of the forum members.

(script-fu-register "script-fu-file-tab" ;func name "File Tab" ;menu label
"Makes a layer into a 'double image flipped'\ format for file tab labels." ;Description "Andrew Dreasler" ;Author
"copyright 2017, Andrew Dreasler" ;copyright notice "February 7, 2017" ;date created "RGB RGBA GRAY GRAYA INDEXED INDEXEDA" ;image type that the script works on SF-IMAGE "img" 0 ;Current Image
)
(define (script-fu-file-tab img) (gimp-image-insert-layer img (car (gimp-layer-copy (car (gimp-image-get-active-layer img)) 0)) 0 -1) (gimp-item-transform-rotate-simple (car (gimp-image-get-active-layer img)) 1 0 601 401) (gimp-image-merge-down img (car (gimp-image-get-active-layer img)) 0) )
(script-fu-menu-register "script-fu-file-tab" "/Layer/Create/Filing")

2017-02-08 13:59:33 UTC (about 8 years ago)
postings
121

Script Help - Basic Macro

I would suggest adding the following two lines at the start of your function::

(gimp-image-undo-group-start image) (gimp-context-push)

and the following two lines at the end:

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

The 'undo' statements allow you to undo the effects of the script with one Ctrl-Z or "Edit/Undo" operation.

The context push and pop statements will preserve the context through your script - not that you are affecting any of the context settings at the moment but you might use this script as the basis for another script in the future. On the other hand you might want a future script to affect one of the context settings.

It took longer than I expected, different sample scripts take different approaches, and it's hard to week out what is and isn't important, but I finally got it worked out.

It's a really limited-purpose script, But I was just looking for a way to speed up the file tab preparation after getting the titles typed up.

Anyway, here's the hot mess of code, for the critique and amusement of the forum members.

(script-fu-register "script-fu-file-tab" ;func name
"File Tab" ;menu label
"Makes a layer into a 'double image flipped'\ format for file tab labels." ;Description "Andrew Dreasler" ;Author
"copyright 2017, Andrew Dreasler" ;copyright notice "February 7, 2017" ;date created "RGB RGBA GRAY GRAYA INDEXED INDEXEDA" ;image type that the script works on
SF-IMAGE "img" 0 ;Current Image
)
(define (script-fu-file-tab img) (gimp-image-insert-layer img (car (gimp-layer-copy (car (gimp-image-get-active-layer img)) 0)) 0 -1) (gimp-item-transform-rotate-simple (car (gimp-image-get-active-layer img)) 1 0 601 401)
(gimp-image-merge-down img (car (gimp-image-get-active-layer img)) 0)
)
(script-fu-menu-register "script-fu-file-tab" "/Layer/Create/Filing")