Post Reply 

Python, get number of layers

Mar 7, 2012, 22:05 (This post was last modified: Mar 7, 2012 22:06 by borko1980.)
Post: #16
RE: Python, get number of layers
Aha, so that means i have to have same number of 'space' characters before 'try' as in before 'except'?
Find all posts by this user
Quote this message in a reply
Mar 7, 2012, 22:38
Post: #17
RE: Python, get number of layers
(Mar 7, 2012 22:05)borko1980 Wrote:  Aha, so that means i have to have same number of 'space' characters before 'try' as in before 'except'?
Yes, spaces. Or tabs. But don't mix them.

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Mar 7, 2012, 22:47
Post: #18
RE: Python, get number of layers
(Mar 7, 2012 21:58)borko1980 Wrote:  Hm, I don't get nothing helpful from console (i am on win7):

??? What this mean?
gimp_wire-read() errors are usually the sign that some plugin went casters up (I think it means Gimp can't read anything from the plugin it started, possibly because said plugin died before answering). The problem may be with another plugin though. Add a deliberate syntax error in your code (like a bunch of *********) and see if you get an identifiable message there.

But as I said above identifying errors is a lot easier on Linux (I also learned Python to script Gimp on a Windows machine). Come to the clear side of the Force, young padawan Smile

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Mar 7, 2012, 23:03
Post: #19
RE: Python, get number of layers
Thanks for your help.
Find all posts by this user
Quote this message in a reply
Mar 8, 2012, 10:21
Post: #20
RE: Python, get number of layers
Ok. I have added horizontal/vertical orientation to be possible to choose in witch way layers will be copied, and moved menu as 'Layer' submenu. The problem now is i don't know how to detect (in python script) if input image is present so i can grey/ungrey option if it is or not?

Current code:
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math
from gimpfu import *

def layers_to_image(timg, tdrawable, orientation):
    
    imgLayers = timg.layers
    numLayers = len(imgLayers)
    if orientation == "horizontal":
        width  = timg.width * numLayers
        height = timg.height
    else:
        width  = timg.width
        height = timg.height * numLayers
    
    image = gimp.Image(width, height, RGB)
    image.disable_undo()
    
    gimp.set_foreground(255, 255, 255)
    gimp.set_background(0, 0, 0)
    
    for i in range(0, numLayers):
        currLayer = timg.layers[i]
        my_layer  = pdb.gimp_layer_new_from_drawable(currLayer, image)
        image.add_layer(my_layer, 0)
        if orientation == "horizontal":
            xoffset   = timg.width * i
            my_layer.translate(xoffset, 0)
        else:
            yoffset   = timg.height * i
            my_layer.translate(0, yoffset)

    pdb.gimp_image_resize_to_layers(image)
    pdb.gimp_image_flatten(image)
        

    image.enable_undo()
    gimp.Display(image)

register(
    "layers_to_image",
    "Copy layers to new image stacked",
    "Copy layers to new image stacked",
    "borko1980",
    "borko1980",
    "2012",
    "<Image>/Layer/_CopyLayersStacked",
    "",
    [
        (PF_RADIO, "orientation", "Orientation", "horizontal",
            (("_horizontal", "horizontal"), ("_vertical", "vertical"))
        )
    ],
    [],
    layers_to_image)

main()
Find all posts by this user
Quote this message in a reply
Mar 8, 2012, 12:35
Post: #21
RE: Python, get number of layers
(Mar 8, 2012 10:21)borko1980 Wrote:  Ok. I have added horizontal/vertical orientation to be possible to choose in witch way layers will be copied, and moved menu as 'Layer' submenu. The problem now is i don't know how to detect (in python script) if input image is present so i can grey/ungrey option if it is or not?
You have no direct control on the menus. You just use a slightly different form of registration:
Code:
register(
    "image_from_layers",
    "Copy layers to image",
    "Copy layers to image",
    "borko1980",
    "borko1980",
        "2012",
        "New image from layers",
        "*",
        [
        (PF_IMAGE, "image", "Input image", None),
        (PF_DRAWABLE, "drawable", "Input drawable", None),
        (PF_RADIO, "orientation", "Orientation", "horizontal",
            (
                ("_horizontal", "horizontal"),
                ("_vertical", "vertical")
            )
        )
        ],
        [],
    image_from_layers,
    menu="<Image>/Image"
)
The "*" above is a filter on the image type (it could be "RGBA", for instance, or "INDEXED"). This makes Gimpp gray out the menu entry for the plugin if the image type doesn't match. If there is no image nothing matches "*" so you are grayed out.

In the registration above, I also moved your plugin under "Image" where it fits better IMHO (after all it's a variation on "Image/Duplicate").

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Mar 8, 2012, 12:53
Post: #22
RE: Python, get number of layers
That's it. Thanks.

Code:
"*"

Is this is regex string?
Find all posts by this user
Quote this message in a reply
Mar 8, 2012, 13:09 (This post was last modified: Mar 8, 2012 13:10 by borko1980.)
Post: #23
RE: Python, get number of layers
Also, i beg you, PLEASEEEEE show me where can i see and learn what parameters and its count is there, for exampe:
Code:
(PF_DRAWABLE,   # i get this one, possible parameters are PF_INT8, PF_COLOR,PF_CHANNEL,PF_FONT...etc

"drawable",  # what about here, what parameters? Must it be in quotes?
"Input drawable" #and here ???
, None #and here???
# how much more???
# whats optional and whats not???
),
Find all posts by this user
Quote this message in a reply
Mar 8, 2012, 13:51
Post: #24
RE: Python, get number of layers
(Mar 8, 2012 13:09)borko1980 Wrote:  Also, i beg you, PLEASEEEEE show me where can i see and learn what parameters and its count is there, for exampe:
Code:
(PF_DRAWABLE,   # i get this one, possible parameters are PF_INT8, PF_COLOR,PF_CHANNEL,PF_FONT...etc

"drawable",  # what about here, what parameters? Must it be in quotes?
"Input drawable" #and here ???
, None #and here???
# how much more???
# whats optional and whats not???
),
On that one I don't know much more than what can be found in http://www.gimp.org/docs/python/index.html Like you I'm a bit cut/pasting from others in that area Smile

For the various constants, import gimpfu and dir(gimpfu) will give you a list....

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Loading PythonFu Plugin: ImportError for .../python/gimp.so (GIMP 2.8.22/OSX/Py2.7.9) joroek 1 120 Jul 11, 2017 07:26
Last Post: ythgilb
  Setting text markup from python script Burbly 1 287 Sep 16, 2014 12:29
Last Post: Burbly
  Python-Fu Script Not Registering image_artist 1 269 Sep 14, 2014 13:24
Last Post: image_artist
  Bashing my head - Batch Python Script nmiltner 1 312 Sep 5, 2014 00:58
Last Post: nmiltner
  Help with python script and drawables nmiltner 3 366 Aug 28, 2014 16:09
Last Post: nmiltner

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS