It is currently 29 Nov 2020, 19:38

• Featuring Members' Works (Image Attachments) •
1: member
2: member
3: member
4: member
5: member

GIMP/GL:  Tutorials | Tips | Questions | Interests | Script Requests
Recommendations:  Index | Top 10
Resources:  🡆 Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Run Code on Visible Layers Script for GIMP

Share your Python Fu Scripts/plug-ins for GIMP here
tim
GL Blogger

Run Code on Visible Layers Script for GIMP

Post#1 by tim » 19 Oct 2017, 20:05


Since there isn't a way to allow users to choose a filter/plug-in/script to run on visible layers (other than having to write a custom script that does it for a specific filter), I thought I'd make a script (for fun or usefulness it's really up to you) that allows you to run your one-liner of python code (which could/should be your desired filter/plug-in/script).
run_code_on_visible_layers.zip
zipped .py file (unzip, put in your GIMP's /plug-ins/ folder)
(1.26 KiB) Downloaded 224 times
run_code_on_visible_layers (2).zip
version 2. Set Active Layer as well so that gmic filter can work on active layer as well.
(1.31 KiB) Downloaded 115 times
run_code_on_visible_layers (3).zip
version 3. Allow selection of all/vislble/not-visible/linked/not-linked layers.
(1.47 KiB) Downloaded 104 times
run_code_on_visible_layers(4).zip
version 4. Layergroup support. Just make sure you run it on an active layer that has no children (to avoid can't pickle error).
(1.68 KiB) Downloaded 143 times
run_code_on_visible_layers.py
version 5. allow the use of '[newline]' and '[tab]' to specify multiline statements
(3.86 KiB) Downloaded 222 times
Script Menu Location: Python-Fu/Run Code on Visible Layers...

Script Options:
Run_Code_on_Visible_Layers_Script_Option.png
Run_Code_on_Visible_Layers_Script_Option.png (24.79 KiB) Viewed 3519 times
Instructions:
1. Turn visibility on for layers that you'd like to run the code on.
2. Determine what code you need to run. In a text editor, type out your code (python) (refer to Help > Procedure Browser).
a) Choose a function that probably starts with "python-fu" or "script-fu". Change all the hyphens (-) in the function name to underscores (_).
b) Add "pdb." in front of your function name.
c) Add parameters after your function. It probably needs an image and a layer as parameters before other parameters, so use "image" and "layer".
d) for example: pdb.script_fu_drop_shadow(image,layer,4,4,15,(0,0,0),60,False)
3. Run script (Python-fu/Run Code on Visible Layers...). Paste your line of code edited from step 2 into the "Code to Run:" option. Click "OK".
4. The Script will try to loop through all your visible layers pointing "layer" to the looped layers, and apply your code to each layer.
5. That's it.

- Example of walk-through on how to create your one-liner code (gimp-threshold).
- Zero01's example of how he successfully created one-liner to use with script after some struggle.
- Example of multi-call one-liner for Pat to Alpha_To_Selection and Pattern_Fill
- Example in Post #8 of filling layers (of current selection) with Color 808080 or RGB(128,128,128)
- Example in Post #12 of filling each layer's content (that isn't transparent) with Color 808080 or RGB(128,128,128)
- Example in Post #13 of filling each layer's alpha locked content with color 808080 (better than post #12 because this method doesn't create visible artifacts around the content's borders as they are partially transparent)
aka Tin

         

Pat625
Tutorial Creator

Post#2 by Pat625 » 20 Oct 2017, 02:56


That is really nice, Tin. I wish I understood some code so that I could use it!

Issabella
Script Tester

Post#3 by Issabella » 20 Oct 2017, 07:37


I think like Pat. I'm sure this new script will be helpful to who knows how to use it. :thumbsup:
Issabella

Don’t be afraid to start over. It’s a new chance to rebuild what you want.

Pat625
Tutorial Creator

Post#4 by Pat625 » 20 Oct 2017, 13:44


I would need a list of codes already written!

tim
GL Blogger

Post#5 by tim » 20 Oct 2017, 14:46


Well if you need a function/filter/script that runs on visible layers, now instead of having to write a custom script ... I can provide you with a one-liner to paste in to use with this script.
So instead of 20 scripts, you'll just have 20 one-liners that you can just look up and choose which to use.
Just let me know what you want and I can quickly provide the 1 liner.
aka Tin

         

tim
GL Blogger

Post#6 by tim » 20 Oct 2017, 14:54


If you're really keen you can try to come up with the one-liners yourself.
For example, you want to do threshold on all visible layers.

in GIMP (Help -> Procedure Browser), type "threshold" you'll see all procedures that has the word threshold in it.
one of which is gimp-threshold.
gimp_threshold_in_procedure_browser.png
gimp_threshold_in_procedure_browser.png (45.91 KiB) Viewed 3463 times
it's called gimp-threshold (so we'll replace the hyphen with underscore so it's gimp_threshold)
now add a "pdb." in front of it so that it's pdb.gimp_threshold.

from the procedure browser, we can see that it takes 3 parameters (drawable, low-threshold, high-threshold)

so we'll use "layer" as the drawable and specify our own low and high thresholds.

so now we can have something like
pdb.gimp_threshold(layer,127,255)

That's it, that's a usable one-liner.
aka Tin

         

Pat625
Tutorial Creator

Post#7 by Pat625 » 19 Nov 2020, 18:57


Tin,
Sorry to bother you but I was not able to make the "Run code on selected layers" work. I am requesting your help.

Need to make a selection on many layers and change the color of the selection, In this case to a gray (808080).

Thank you and appreciate your help in advance.


tim
GL Blogger

Post#8 by tim » 20 Nov 2020, 03:40


@Pat625 ,
Here you go, make your selection first, then run plug-in and use the below one-liner (2 statements separated by semicolon)

Code: Select all

pdb.gimp_context_set_foreground((128,128,128));pdb.gimp_edit_fill(layer,FOREGROUND_FILL);
aka Tin

         

Pat625
Tutorial Creator

Post#9 by Pat625 » 20 Nov 2020, 07:05


How do I make the selection? Each layer is different.

tim
GL Blogger

Post#10 by tim » 20 Nov 2020, 13:09


oh if selection on each layer is different then you have to be able to do it manually as there's no existing way of telling the code to tell it to select unless there was a way to automate the selection. How are you selecting on each layer now? manually?
The code doesn't know what you want as selection on each layer.
Unless you're doing selection by color or something that we can tell it in logics otherwise it won't know what you want to turn to gray.
aka Tin

         


GIMP/GL:  Tutorials | Tips | Questions | Interests | Script Requests
Recommendations:  Index | Top 10
Resources:  🡆 Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Post Reply New Topic
  • Similar Topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 32 guests