Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
changing active layers
#6
(01-29-2023, 05:25 PM)programmer_ceds Wrote:
(01-29-2023, 12:47 PM)salamander017 Wrote: Hello, thank you for your time.
Regarding that, the error says:
  GIMP Error
Execution error for 'Set active layers':
Error: Invalid type for argument 2 to gimp-image-set-active-layer
I think that the problem is that gimp-image-get-layers returns two parameters - the first is the number of layers and the second is an int32 array of the layer IDS (see the description of gimp-image-get-layers in the PDB browser).

So your code is assigning the number of layers to layer1, not the ID of the first layer.

Try replacing the assignments that set layer1 and layer2 with:

(num_layers (cad (gimp-image-get-layers image)))
(layers (cadr (gimp-image-get-layers image)))

then:

(layer1 (aref layers 0))
(layer2 (aref layers 1))



However, it would be better code to set layer1 and layer2 (using the set! statement) after your let* statement - having checked that the image does actually have 2 (or possibly, depending on your needs) at least 2 layers before proceeding - report an error if there are not 2 layers, then your script can fail gracefully if it activated with just the one layer.
Thank you very much for the explanation.


Is there a way to run gimp procedures using the script-fu console? Or, how do I test what parameters are returned when using a gimp procedure?

(01-29-2023, 09:10 PM)Ofnuts Wrote: You don't need to set active layers...  The layer argument of the (plugin-exchange) is the layer on which it will act, so this should be layer1 or layer2.

Otherwise, without changing colors, if you change the top layer to Difference blend mode, you will get white spots where the layers differ.

Oh, thank you very much for that. I have modified the code based on your suggestion. But now, when running the script, a dialog pops up and makes me choose between the layers.
But I prefer if it did not.
If I choose the top layer, only the blue to the top is applied. If I choose the bottom layer, all is applied correctly. (the top layer must be active)
When the active layer is the second layer. The colors are reversed and multiply is applied to the bottom layer instead.

(define (script-fu-gimpcompare image layer1 layer2)
  (plug-in-exchange RUN-NONINTERACTIVE image layer1 0 0 0 0 0 255 0 0 0)
  (plug-in-exchange RUN-NONINTERACTIVE image layer2 0 0 0 255 0 0 0 0 0)
  (gimp-layer-set-mode layer1 LAYER-MODE-MULTIPLY)
  (gimp-displays-flush)
)

(script-fu-register 
  "script-fu-gimpcompare"
  "<Image>/Script-Fu/gimpcompare"
  "blue red multiply"
  "Test"
  "Test"
  "2022"
  "RGB*"
  SF-IMAGE "Image" 0
  SF-DRAWABLE "layer1" 0
  SF-DRAWABLE "layer2" 0

)
Reply


Messages In This Thread
changing active layers - by salamander017 - 01-29-2023, 06:54 AM
RE: changing active layers - by programmer_ceds - 01-29-2023, 10:57 AM
RE: changing active layers - by salamander017 - 01-29-2023, 12:47 PM
RE: changing active layers - by programmer_ceds - 01-29-2023, 05:25 PM
RE: changing active layers - by salamander017 - 01-30-2023, 01:35 PM
RE: changing active layers - by Ofnuts - 01-31-2023, 11:25 AM
RE: changing active layers - by salamander017 - 02-01-2023, 09:35 AM
RE: changing active layers - by programmer_ceds - 02-01-2023, 09:54 AM
RE: changing active layers - by salamander017 - 02-01-2023, 10:40 AM
RE: changing active layers - by Ofnuts - 01-29-2023, 09:10 PM

Forum Jump: