Gimp-Forum.net
small plugin code help - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions)
+---- Thread: small plugin code help (/Thread-small-plugin-code-help)

Pages: 1 2


RE: small plugin code help - Ofnuts - 03-02-2024

(03-02-2024, 03:35 AM)gimpygirl Wrote: But this function is tje same as "select by color" tool in gimp, right?
Because that is what i want.

Yes...


RE: small plugin code help - gimpygirl - 03-02-2024

I don't understand how the selection is "passed" to the clear function

So I select all black pixels

Code:
pdb.gimp_image_select_color(image, CHANNEL_OP_REPLACE, image.active_layer, (0, 0, 0))
Now I want to delete the selection


Code:
pdb.gimp-drawable-edit-clear(???)

what parameter to insert there? The selection is made in the previous line but where is it now?


RE: small plugin code help - MrsP-from-C - 03-02-2024

drawable ?
tdrawable ?

depends on what you named it


RE: small plugin code help - Ofnuts - 03-02-2024

[attachment=11353]

You Pass a drawable (so, your layer, likely)


For most operations (manual or in scripts), the selection is implicit. The selection applies to the pixels of the current "drawable" that are also included in the selection mask. The only exception to this rule is that for paint/delete operations, if the selection is completely empty, it behaves as if everything was selected. So once you have created a selection, everything you do next is constrained to that selection , until your use pdb.gimp_selection_none(image) to clear the selection.


RE: small plugin code help - gimpygirl - 03-02-2024

(03-02-2024, 08:58 PM)Ofnuts Wrote: You Pass a drawable (so, your layer, likely)


For most operations (manual or in scripts), the selection is implicit. The selection applies to the pixels of the current "drawable" that are also included in the selection mask. The only exception to this rule is that for paint/delete operations, if the selection is completely empty, it behaves as if everything was selected. So once you have created a selection, everything you do next is constrained to that selection , until your use pdb.gimp_selection_none(image) to clear the selection.

If I first do this line:


Code:
pdb.gimp_image_select_color(image, CHANNEL_OP_REPLACE, image.active_layer, (0, 0, 0))

then this to delete the selection above


PHP Code:
pdb.gimp-drawable-edit-clear(image.active_layer


Is this the correct parameter?

When the 2nd line is run, I get error in the error console.
The error appears on the 2nd line, the first line works.


translation:
gimp error
call error for procedure 'gimp-procedural-db-proc-info':
procedure 'gimp' is not found

No idea what this error means...


RE: small plugin code help - Ofnuts - 03-03-2024

This is because you used dashes (gimp-drawable-edit-clear) instead of underscores: (gimp_drawable_edit_clear). For Python you are therefore trying to subtract a variable called drawable from pdb.gimp. The Python doc is auto-generated and since the same text is used for script-fu and python-fu, there are things to adapt:
  • all dashes become underscores
  • object IDs in script-fu are plain objects in Python (so you get a gimp.Image object, not an integer)
  • when there is no object instead of using the -1 ID you use None
Also, don't use image.active_layer. If you script registration is correct, your script is passed a layer as the second argument and this is the layer you should work with. Using image.active_layer doesn't do you any good because if the active drawable isn't a layer (because it is a mask/channel), then image.active_layer returns None.


RE: small plugin code help - gimpygirl - 03-03-2024

(03-03-2024, 12:35 AM)Ofnuts Wrote: This is because you used dashes (gimp-drawable-edit-clear) instead of underscores: (gimp_drawable_edit_clear). For Python you are therefore trying to subtract a variable called drawable from pdb.gimp. The Python doc is auto-generated and since the same text is used for script-fu and python-fu, there are things to adapt:
  • all dashes become underscores
  • object IDs in script-fu are plain objects in Python (so you get a gimp.Image object, not an integer)
  • when there is no object instead of using the -1 ID you use None
Also, don't use image.active_layer. If you script registration is correct, your script is passed a layer as the second argument and this is the layer you should work with. Using image.active_layer doesn't do you any good because if the active drawable isn't a layer (because it is a mask/channel), then image.active_layer returns None.

You really give great answers.

What parameters the method used in 'register' must have? First image, second drawable or are there more options?
How do you know what parameters you must use?

What layer is passed to the drawable parameter by gimp?
Suppouse I open an image with 4 layers. Which one is it? Always the first? And is the first the lowest or highest in the GUI?

This is still very unclear for me: what parameters in the 'register' method you need and what is passed by gimp to them?


RE: small plugin code help - Ofnuts - 03-03-2024

(03-03-2024, 01:42 AM)gimpygirl Wrote:
(03-03-2024, 12:35 AM)Ofnuts Wrote: This is because you used dashes (gimp-drawable-edit-clear) instead of underscores: (gimp_drawable_edit_clear). For Python you are therefore trying to subtract a variable called drawable from pdb.gimp. The Python doc is auto-generated and since the same text is used for script-fu and python-fu, there are things to adapt:
  • all dashes become underscores
  • object IDs in script-fu are plain objects in Python (so you get a gimp.Image object, not an integer)
  • when there is no object instead of using the -1 ID you use None
Also, don't use image.active_layer. If you script registration is correct, your script is passed a layer as the second argument and this is the layer you should work with. Using image.active_layer doesn't do you any good because if the active drawable isn't a layer (because it is a mask/channel), then image.active_layer returns None.

You really give great answers.

What parameters the method used in 'register' must have? First image, second drawable or are there more options?
How do you know what parameters you must use?

What layer is passed to the drawable parameter by gimp?
Suppouse I open an image with 4 layers. Which one is it? Always the first? And is the first the lowest or highest in the GUI?

This is still very unclear for me: what parameters in the 'register' method you need and what is passed by gimp to them?
  • Typically, the first two parameters are Image and layer/drawable (if the script is supposed to modify a drawable/layer). When your registration starts with these two, Gimp prefills them with the active image and active drawable in the image. 
  • Other parameters depend on functionality: if you want to use your script on another image, what will change? The size of the tiles? The position of the top left corner? The width/height of some space between tiles that should be skipped? The output directory? Anything that you think could change between two uses of the script is a possible parameter. After that you have to stroke a balance between a script that covers most cases and a script that as so many parameters that the dialog doesn't fit on a screen...
[attachment=11359]

[attachment=11360]