GIMP Python-Fu script does not run with more than 4 parameters

670 Views Asked by At

I am trying to write a Python-Fu plugin for GIMP, but adding more than 4 input parameters (including the Image and Drawable parameters) will cause the script to not run at all. I have tried this with various input parameter types and they all produce the same result. Does anyone have some insight as to why this is happening? Am I missing something obvious?

register(
"python_fu_guide_maker",
"Guide Maker",
"Creates guides with specified spacing.",
"MrKagouris", "", "2017",
"Guide Maker",
"*",
[
    (PF_IMAGE, "image", "Input Image", None),
    (PF_DRAWABLE, "drawable", "Input Layer", None),
    (PF_INT, "hspace", "Horizontal Spacing", None),
    (PF_INT, "vspace", "Vertical Spacing", None),
    (PF_BOOL, "percent", "By percent?", None)
],
[],
guide_maker,
menu="<Image>/Image/Guides"
)

EDIT:

Below is the full, fully functional script including the Python code.

#!/usr/bin/env python

from gimpfu import *

def guide_by_num(image, hspace, vspace):
    imageHeight = pdb.gimp_image_height(image)
    imageWidth = pdb.gimp_image_width(image)
    if (hspace <= 0 or vspace <= 0):
        return                          # Input validity check.
    hGuides = int(imageHeight/hspace)   # Calculates the
    vGuides = int(imageWidth/vspace)    # number of guides.
    for i in range(2):
        pdb.gimp_image_add_hguide(image, i * imageHeight)   # Adds guides to
        pdb.gimp_image_add_vguide(image, i * imageWidth)    # image edges.
    for i in range(1, hGuides):                         # Adds the horizontal
        pdb.gimp_image_add_hguide(image, i * hspace)    # guides.
    for i in range(1, vGuides):                         # Adds the vertical
        pdb.gimp_image_add_vguide(image, i * vspace)    # guides.

def guide_by_percent(image, hspace, vspace):    #Not used.
    imageHeight = pdb.gimp_image_height(image)
    imageWidth = pdb.gimp_image_width(image)
    hspace = int(hspace * (imageWidth * 0.01))
    vspace = int(vspace * (imageHeight * 0.01))
    if (hspace <= 0 or vspace <= 0):
        return
    hGuides = int(imageHeight/hspace)
    vGuides = int(imageWidth/vspace)
    for i in range(2):
        pdb.gimp_image_add_hguide(image, i * imageHeight)
        pdb.gimp_image_add_vguide(image, i * imageWidth)
    for i in range(1, hGuides):
        pdb.gimp_image_add_hguide(image, i * hspace)
    for i in range(1, vGuides):
        pdb.gimp_image_add_vguide(image, i * vspace)

def guide_maker(image, drawable, hspace, vspace):
    guide_by_num(image, hspace, vspace)

register(
    "python_fu_guide_maker",
    "Guide Maker",
    "Creates guides with specified spacing.",
    "MrKagouris", "", "2017",
    "Guide Maker",
    "*",
    [
        (PF_IMAGE, "image", "Input Image", None),
        (PF_DRAWABLE, "drawable", "Input Layer", None),
        (PF_INT, "hspace", "Horizontal Spacing", None),
        (PF_INT, "vspace", "Vertical Spacing", None),
        #(PF_BOOL, "percent", "By percent?", None)
    ],
    [],
    guide_maker,
    menu="<Image>/Image/Guides"
    )

main()
1

There are 1 best solutions below

2
On BEST ANSWER

You have to use integer default values in the registration, not None:

[
    (PF_IMAGE, "image", "Input Image", None),
    (PF_DRAWABLE, "drawable", "Input Layer", None),
    (PF_INT, "hspace", "Horizontal Spacing", 0),
    (PF_INT, "vspace", "Vertical Spacing", 0),
    (PF_BOOL, "percent", "By percent?", 1)
],

enter image description here