It is currently 19 Feb 2018, 17:44

GIMP/GL QuestionsPython-fu undo and delete layer (Showcase | Slideshow)

GIMP or GIMP LEARN forum related Questions
Post Reply
No avatar
BrianStu

Forum Member
View: Showcase | Slideshow
Topic Posts: 2/4
Posts: 2
Joined: 13 Feb 2018, 19:07
Cash on hand: 181.64 GLP
Great Britain

Python-fu undo and delete layer

Post#1 by BrianStu » 5 days 21 hours ago


Hi,
I've changed the Subject from autocrop to undo and delete layer as this better describes the issue.


I've been playing with GIMP on and off for a few years but never had any contact with scripts - until now.

I've been playing about with simple python-fu scripts and am now trying to produce something to meet my needs.
It involves cropping a load of image files (have scanned loads of my 35mm negatives).

I've managed to create a batch script which allows the selection of all image files in a directory (and subdirectories if required).
Each file is opened, processed and saved and the operations and statistics are written to a log file.

In the processing a number of actions are performed, mostly working OK but I'm struggling with 2 specific items.

1. I have created a number of layers and wish to perform an autocrop based upon one of the layers.
pdb.plug_in_autocrop_layer(image, drawable) seemed to be a suitable choice and works fine
The problem is that I then interrogate the width and height of the layer and if the image has shrunk by more than
a specific percentage of the original, then I wish to UNDO the autocrop. This doesn't seem possible so I perform this function
on a newly created (temporary) layer which I can delete.

2. Trying to DELETE a specific LAYER.
pdb.gimp_layer_delete(item) seemed the obvious answer but is deprecated and the alternative is
pdb.gimp_item_delete(item). The problem is I can't get this to work, it complains about the ITEM
I've tried using the layer variable name, the image.layer name etc but I cant find the right ID for the ITEM

The following code is used to create a temporary layer
tmp_layer = pdb.gimp_layer_copy(image.active_layer, False)
tmp_layer.name = 'temp'
image.add_layer(tmp_layer, -1)
I've tried the following to later delete it
pdb.gimp_item_delete(tmp_layer) ----- gives RuntimeError: execution error
pdb.gimp_item_delete(image.active_layer) ------ gives RuntimeError: execution error

I've found a solution using
image.remove_layer(tmp_layer) --- which works, but why can't I get this to work using pdb.gimp_item_delete(ITEM)
The reason I ask is that there are many plug-ins in the Procedure Browser which require a parameter ITEM.

Many thanks to anyone who can tell me where I'm going wrong.... I'm sure it's something daft and simple.
0 x




Registered members enjoy ads-free content
User avatar
tim
Administrator
View: Showcase | Slideshow
Topic Posts: 2/4
Posts: 2157
Joined: 26 Sep 2016, 00:16
Cash on hand: 7,894.01 GLP
Bank: 51,356.25 GLP
Gender: Guy
Location: Victoria, BC
Website: https://gimplearn.net
Operating System: Windows
GIMP Version: 2.8.22
My Personal Blog
My FineArtAmerica
x 1196
x 256
Contact:
Canada

Post#2 by tim » 5 days 13 hours ago


Look into using pdb.gimp_image_remove_layer() instead.
I was never able to get delete layer to work so...

UPDATE: I see you used remove_layer at bottom that should do the job. I have no idea why delete doesn't work and gave up with it long time ago. :D
0 x



aka Tin
Image gimplearn.net                                              

No avatar
BrianStu

Forum Member
View: Showcase | Slideshow
Topic Posts: 2/4
Posts: 2
Joined: 13 Feb 2018, 19:07
Cash on hand: 181.64 GLP
Great Britain

Post#3 by BrianStu » 5 days 8 hours ago


Thanks for the reply.
I thought I was doing something wrong.
Being new to this I just don't know all the commands (methods?).
I was using the browse button in the python-fu console to search for available statements, double clicking to get the syntax to paste into my script.
I spent days... looking for a way to do many things.
When you feel like you're getting nowhere, you try to find another way of doing the task, only to be confronted by another problem and more days.

In looking into cropping I found the autocrop single layer command. I was unable to find a normal crop that works on a single layer. Is there one?
Something like... crop_layer(image.layer, x, y ,width,height)

I'm using Linux ( Ubuntu 16.04) with gimp 2.9.8
0 x




User avatar
tim
Administrator
View: Showcase | Slideshow
Topic Posts: 2/4
Posts: 2157
Joined: 26 Sep 2016, 00:16
Cash on hand: 7,894.01 GLP
Bank: 51,356.25 GLP
Gender: Guy
Location: Victoria, BC
Website: https://gimplearn.net
Operating System: Windows
GIMP Version: 2.8.22
My Personal Blog
My FineArtAmerica
x 1196
x 256
Contact:
Canada

Post#4 by tim » 5 days 2 hours ago


I don't think there's single layer crop command, i only see gimp_image_crop
you might want to try gimp_layer_resize
0 x



aka Tin
Image gimplearn.net                                              

Post Reply

Last 20 Members Who Visited This Topic

User avatar gnerd (2), User avatar tim (10), User avatar RJKD (1), BrianStu (13), User avatar Conbagui (1), User avatar Pat625 (1)

  • Similar Topics
    Replies
    Views
    Last post
• Featuring Members' Works (Image Attachments Only) •
1: gnerd
2: Pat625
3: Issabella
4: Pat625
5: Issabella
6: Issabella
7: Pat625

Who is online

Users browsing this forum: No registered users and 1 guest