togakangaroo wrote:
Thanks for the reply. Does the fact that I do
(car (gimp-image-get-layers 1))
Not get the first (and in this case, only) layer? What is car returning then?
'gimp-image-get-layers' returns a list containing two elements. The second element of the list is an array of layer-IDs, and the first element is the number of layer-IDs in the array.
The first element (the number of layer-IDs) is provided for those programming languages (such as C) that do not know the size of an array. Script-fu, however, is always able to determine the size of an array (or a list) without needing a separate variable to keep track of it. This means that you can safely ignore the first element of the return value.
The second element of the returned list (i.e., the actual array of layer-IDs) can be accessed by taking the 'car' of the 'cdr' of the returned list, which can be abbreviated to the 'cadr'. The PDB "int32array" is converted to a Script-fu 'vector' before it is returned, and there a few different procedures available for working with a Scheme vector. The most important of these are:
- (vector-length v) -- return the number of elements in vector 'v'
- (vector-ref v n) - return the n'th element in the vector. The parameter 'n' should be in the range 0 to one less than the number of elements in the vector (in other words, the 'vector-length'); with n=0 being the first element and n=vector-length - 1 being the last.
- (vector-set! v n x) - set the value of the n'th element to 'x'. 'x' can be of any type you want, a number, a string, a list, even another vector.
- (vector->list v) - return a list having the same elements as the vector 'v'.
So to find the first (or only) layer in an image, you could use the expression:
(vector-ref (cadr (gimp-image-get-layers image)) 0)