Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dynamics not working in gimp-drawable-edit-stroke-item
#1
I want to draw perpendicular lines to a path within a selection. This can be done in gimp by selecting the right brush with the correct settings and then stroking a path with the the paintbrush or pencil. When I try to use the same settings in python-fu the stroked portion simply stays vertical. I have noted that during the manual stroke selection there is an "Emulate brush dynamics" option which is selected. I cannot find a similar setting in the python-fu api.
There might be some other issues in the script since this is my second python-fu script:

Code:
#!/usr/bin/env python

# GIMP Python plug-in template.

from gimpfu import *

def hay_selection(img, layer) :
    gimp.progress_init("Finding next tree ring " + layer.name + "...")

    # Set up an undo group, so the operation will be undone in one step.
    pdb.gimp_undo_push_group_start(img)

    # Do stuff here.
    pdb.gimp_context_push()
    # Base grey color
    pdb.gimp_context_set_foreground(gimpcolor.RGB(224,224,224))
    pdb.gimp_drawable_edit_fill(layer, FOREGROUND_FILL)
    # Path around selection
    pdb.plug_in_sel2path(img, layer)
    np = pdb.gimp_image_get_active_vectors(img)
    pdb.gimp_context_set_foreground(gimpcolor.RGB(0,0,0))
    pdb.gimp_context_set_paint_method("gimp-paintbrush")
    pdb.gimp_context_set_brush("2. Block 03")
    pdb.gimp_context_set_dynamics("Track Direction")
    pdb.gimp_context_set_brush_aspect_ratio(-20)
    pdb.gimp_context_set_brush_size(15)
    pdb.gimp_context_set_brush_angle(0)
    pdb.gimp_context_set_brush_spacing(10)
    pdb.gimp_context_set_brush_hardness(1)
    pdb.gimp_context_set_stroke_method(1)
    pdb.gimp_message("Dynamics: " + pdb.gimp_context_get_dynamics())
    pdb.gimp_drawable_edit_stroke_item(layer,np)
    # Fill interior with Hay Small
    pdb.gimp_context_set_pattern("Hay Small")
    pdb.gimp_selection_shrink(img,7)
    pdb.gimp_drawable_edit_fill(layer, PATTERN_FILL)    

    # Cleanup
#    pdb.gimp_image_remove_vectors(img,np)
    pdb.gimp_context_pop()

    # Close the undo group.
    pdb.gimp_undo_push_group_end(img)

register(
    "python_fu_hay_selection",
    "Selection to Hay",
    "Adds edge and fill to selection for hay.",
    "jonker",
    "jonker",
    "2024",
    "<Image>/Python-Fu/Selection to Hay...",
    "*",      # Alternately use RGB, RGB*, GRAY*, INDEXED etc.
    [],
    [],
    hay_selection)

main()
Reply
#2
The doc in the PDB browser doesn't mention dynamics in the context settings that affect the call.

I have a script that does something like this (ofn-brush-strokes-on-path), and it computes and sets the brush angle before each stroke.
Reply
#3
Thank you for the response.  I thought dynamics might work since that is the default. Oh well.

I rewrote the code calling ofn-brush-strokes-on-path.  It is working now, except for the undo groups.  It seems like I cannot use the undo groups now that I am calling ofn-brush-strokes-on-path.  It won't even let me start and stop the undo before or after the call. Any suggestions on that would be appreciated.


Code:
#!/usr/bin/env python

# GIMP Python plug-in template.

from gimpfu import *

def hay_selection(img, layer) :
    gimp.progress_init("Turning into Hay Pile " + layer.name + "...")

    # Set up an undo group, so the operation will be undone in three steps.
    # This is the interior undo step
#    image.undo_group_start()

    # Do stuff here.
    gimp.context_push()
    # Base gray color
    pdb.gimp_context_set_foreground(gimpcolor.RGB(224,224,224))
    pdb.gimp_drawable_edit_fill(layer, FOREGROUND_FILL)
    # Path around selection
    pdb.plug_in_sel2path(img, layer)
    outerpath = pdb.gimp_image_get_active_vectors(img)
    # Fill interior with Hay Small
    pdb.gimp_context_set_pattern("Hay Small")
    pdb.gimp_selection_shrink(img,7)
    pdb.gimp_drawable_edit_fill(layer, PATTERN_FILL)
    # Inner Path
    pdb.plug_in_sel2path(img, layer)
    innerpath = pdb.gimp_image_get_active_vectors(img)
    #Build Rim Selection
    pdb.gimp_image_select_item(img,CHANNEL_OP_REPLACE,outerpath)
    pdb.gimp_image_select_item(img,CHANNEL_OP_SUBTRACT,innerpath)
    pdb.gimp_context_set_foreground(gimpcolor.RGB(0,0,0))
    pdb.gimp_context_set_paint_method("gimp-paintbrush")
    pdb.gimp_context_set_brush("2. Block 03")
    pdb.gimp_context_set_brush_aspect_ratio(-20)
    pdb.gimp_context_set_brush_size(15)
    pdb.gimp_context_set_brush_angle(0)
    pdb.gimp_context_set_brush_hardness(1)
    # Close the undo group to allow brush strokes to work
#    image.undo_group_end()
    pdb.gimp_layer_resize_to_image_size(layer)
    pdb.python_fu_ofn_brush_strokes_on_path(img,layer,0,4,1,0,100,4,'{pathName}-{brush1}/{count}')
    pdb.plug_in_autocrop_layer(img,layer)
    
    # Cleanup
    # This is the cleanup undo step
#    image.undo_group_start()
    pdb.gimp_image_select_item(img,CHANNEL_OP_REPLACE,outerpath)
    pdb.gimp_image_remove_vectors(img,innerpath)
    pdb.gimp_image_remove_vectors(img,outerpath)
    gimp.context_pop()
    # Close the cleanup undo group.
#    image.undo_group_end()

register(
    "python_fu_hay_selection",
    "Selection to Hay",
    "Adds edge and fill to selection for hay.",
    "Jonker",
    "Jonker",
    "2024",
    "<Image>/Python-Fu/Selection to Hay...",
    "*",      # Alternately use RGB, RGB*, GRAY*, INDEXED etc.
    [],
    [],
    hay_selection)

main()
Reply
#4
Hmm. As far as I know you can nest undo group (ie, yours, and mine nested in it). What do you means by " It won't even let me start and stop the undo before or after the call"?
Reply
#5
If I uncomment the undo_group_start and undo_group_end then the script silently does nothing. Wondering if nesting was a problem, I setup an undo_group_start and then before calling the ofn_brush_strokes_on_path I ran an undo_group_end. This removed the nesting question.  The silent quitting remained.  The only way to get the script to work is if I avoid working with the undo group. With the undo_group commands commented out, as shown above, the script runs fine.

Right now I am wondering if there is some sort of problem with included files or something like that.
Reply
#6
In your code I see image.undo_group_start() but you image variable is called img so that should be img.undo_group_start() (and of course img.undo_group_end()) You can also add a try/except block in your code to catch all errors and report them with a gimp.message().
Reply
#7
Of course!  I should have seen that.  Thank you it is working fine nested now.  Thank you so much for your help.
Reply


Forum Jump: