Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Fu process questions.
#1
I am trying to automate a simple process, but, I am new to script-fu and trying to get my bearings.
I am going to describe what I am trying to do, where I am failing, and perhaps find an example to what I am trying to do.

The Task
I have an image (myimage.xcf) which has a background layer (256 by 256, RGB, background transparancy)
as well as 200 "mask" layers 

The background image is a texture (think carpet or steel image)

The mask layers have two colors - black and white 


The Process
This script need to run against the currently selected image, non-interactively

For each of the mask layers (named mask1, mask2 etc)
 The script will make a copy of the background layer called "current work"
  Using the current mask, it will select by color (black) switch to the "current work" layer and apply the script-fu-add-bevel 
  The script will then go back to the current mask layer and select by color(white), switch to the "current work" layer and delete the selection 
  The script will then export the "current work" to a png file, delete the "current work" layer and repeat the process for the next mask layer.

The Problem

The thing is, while I know I can refer to layers by number, how do I find a layers ID by name ie
While I can use  (gimp-image-get-active-drawable 1) to get the layer number for the currently selected layer, how do I get the layer number for the layer named "background"?
I can set a layer manually at position 0, but, I can't find instructions on how to switch layers based upon position or to switch layers based upon name.

I wish there was a "recorder" process that just created a script that repeated what the user was doing like a macro, but, I can not find such a thing and it is beyond my ability to write it.

Any guidance on how to associate a layer(items) number based upon it's name or it's position in the layer list, would be appreciated.

Thanks in advance
Reply
#2
See gimp-image-get-layer-by-name. You can also get list/vector of all the layers in the image and iterate it. The background layer is the mast in the list (first is the top layer).

In the API you don't really "switch" layers, because there is no implicit active layer as you have in the UI. instead every call that involves a layer takes the target layer ID as an argument (the "drawable", in your case).

You can very likely simplify your process because if your mask layers are black and white, after you have a selection on the black you can obtain a selection on the white by just inverting the selection.
Reply


Forum Jump: