Post Reply 

Get current image with script-fu?

Jun 11, 2014, 02:18
Post: #1
Get current image with script-fu?
Hi there, I'm a long time GIMP user and I decided to start making a script to help me perform some repetitive functions for me. I'm no stranger to programming and I'm pretty sure I understand how script-fu generally works.

However, I can't find out how to get the current/active image's ID. That is, the one the user is currently viewing. I'd imagine this would be fairly straightforward, can anybody point me in the right direction?
Find all posts by this user
Quote this message in a reply
Jun 11, 2014, 06:34
Post: #2
RE: Get current image with script-fu?
If you have a look at the basic Scheme tutorial on the GIMP web-site, it shows how you write a script that is passed the image (and drawable) id from the script-dialog window.

http://www.gimp.org/tutorials/Basic_Scheme/

Kevin
Find all posts by this user
Quote this message in a reply
Jun 11, 2014, 22:39
Post: #3
RE: Get current image with script-fu?
Thanks guys! After I posted I actually took a second look at the Basic Scheme tutorial as paynekj suggested and found my answer, apparently I managed to miss it the first time round. I didn't have time to post that I'd figured it out though.

I do have another question though, of a different nature, and I'm not sure if I should make a new thread (please say if I should) but here it is anyway:

Is there a way to make a script-fu tool that I can simply use by selecting the tool and clicking on the image, which then passes through the cursor's coordinates? Similar to any of the built-in tools, but then it uses the coordinates to do my custom function.

If this isn't possible in script-fu, can I do it with Python?
Find all posts by this user
Quote this message in a reply
Jun 13, 2014, 07:52
Post: #4
RE: Get current image with script-fu?
Well I've decided to just use the top-left corner of a rectangular selection for the coordinates, that shouldn't really be an issue since it's for a specific purpose so only me and perhaps a few other people will use it.

Is Python also quicker with processing long tasks? For instance would it be faster to go through and check every pixel in an image? (Of course I don't plan to do exactly that but my plugin will go through some fairly long loops.) If so I might consider using that then, I picked up script-fu in less than 2 days so if Python is easier it shouldn't take too long either.
Find all posts by this user
Quote this message in a reply
Jun 13, 2014, 23:56
Post: #5
RE: Get current image with script-fu?
Well I've got Python figured out and you're right, it is much easier than script-fu. I am having some trouble though, if I try to do anything like for loop or conditional (if) statement, it says the "plugin crashed" when I try to run it. For example, this runs:

Code:
def iconMaker(img, drawable):
    bounds = pdb.gimp_selection_bounds(img)
    
    print bounds[0]

But this doesn't:

Code:
def iconMaker(img, drawable):
    bounds = pdb.gimp_selection_bounds(img)
    
    if true
        print bounds[0]

Am I doing something wrong?
Find all posts by this user
Quote this message in a reply
Jun 14, 2014, 01:29
Post: #6
RE: Get current image with script-fu?
Ah right, I must have missed the colon when looking up references! Works great now, thanks.

Also thanks for that tip, I was wondering if there's a good way to debug Python scripts. Hopefully I should be able to start properly working on it now!
Find all posts by this user
Quote this message in a reply
Jun 14, 2014, 23:36
Post: #7
RE: Get current image with script-fu?
Yeah, printing is invaluable, many a time has it allowed me to pinpoint which part of complex code is causing an error-less crash (or on which iteration of a loop it's happening). I realised print isn't showing anything so I've been using gimp_message(), but I didn't know about the Error console, thanks! I've also decided to wrap gimp_message() in my own trace() function, to make it a bit quicker to write.
Find all posts by this user
Quote this message in a reply
Jun 15, 2014, 01:26
Post: #8
RE: Get current image with script-fu?
Does the python-fu console display print/gimp_message()? As far as I could tell it only displays return values.
Find all posts by this user
Quote this message in a reply
Jun 15, 2014, 23:37
Post: #9
RE: Get current image with script-fu?
I see, that's interesting! I might give that a shot sometime then, it'd be especially handy when doing some complex stuff and gimp_message() just won't cut it.

In any case thanks for all your help, I got my plugin done and working!
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Any plugin for open multiple image in paint.net shinprog 1 364 Oct 31, 2017 11:38
Last Post: paynekj
  Scale image to specific size MattRothschild 1 241 Sep 15, 2017 11:13
Last Post: ythgilb
  Request for script chlebna 1 195 Sep 13, 2017 09:35
Last Post: ythgilb
  Request for script - Guillotine + Watermark sunslick 1 254 Sep 4, 2017 08:51
Last Post: ythgilb
  Script-fu: How to create new, addressable layer using gimp-floating-sel-to-layer Bertholom√§us 1 274 Aug 31, 2017 14:32
Last Post: Bertholomäus

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS