Re: [Gimp-developer] pdb.gimp_get_item_by_id(), or ids and layers and layer groups
On Mon, Feb 7, 2011 at 8:44 PM, saulgo...@flashingtwelve.brickfilms.com wrote: Quoting Javier Candeira jav...@candeira.com: On Mon, Feb 7, 2011 at 2:30 AM, saulgo...@flashingtwelve.brickfilms.com wrote: The PDB functions already exist for handling layer groups, and Script-fu does not have any problem making use of these functions. The Python-fu extension has not yet been updated to handle groups (there is no 'group' class). Do you mean that the Python-fu extension doesn't yet have access to the proper script-fu functions from pdb? Not exactly. In Python, a layer is a reference to a data structure (in C terminology, a pointer to a struct). One of the fields is the layer's ID number. The PDB only deals with these ID numbers, and Python doesn't provide a direct way to handle IDs. The only thing you could do is get a list of all layers/groups (which would be a list of pointers to structures) and search that list for the structure containing the appropriate ID. Since the 'gimp-image-get-layers' procedure now only returns the IDs of the top-level layers/groups, there is no way to perform such a search. At some point, this will be remedied but to my knowledge there is currently no way to do what you want with Python. Script-fu does not encounter this problem because there is no Script-fu data structure for a layer -- a layer is identified by the same ID number that the PDB uses. It does not matter that the layer IDs returned by 'gimp-image-get-layers' might actually be group IDs, to Script-fu it is just a number. Script-fu can pass that same number back to the PDB and the procedure will know what to do with it (for example, a call to 'gimp-item-is-group ID-number' will inform Script-fu that the ID belongs to a group object). Thank you, thank you so much. You may have saved my bacon already, just with this explanation. The rest is (very good) gravy. Back to the code grindstone now... Javier ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
[Gimp-developer] pdb.gimp_get_item_by_id(), or ids and layers and layer groups
First of all, a big thank you to the developers for an great image editing program. I am writing a python-gimp export script for an animation tool, using Ubuntu 10.10 maverick with Gimp version 2.7.3 from this ubuntu PPA, which is not a nightly build of your devel tree, but close enough: https://launchpad.net/~matthaeus123/+archive/mrw-gimp-svn The workflow expects a gimp document's layers to be exported as a tree of files, where the directory structure is determined by the document's layer groups. So, if group panel_1 has sublayers foo and bar, and group panel_2 has sublayers blargh and foobar, the expected output looks like this: $ tree exported_layers exported_layers |-- panel_1 | |-- bar.png | `-- foo.png `-- panel_2 |-- blargh.png `-- foobar.png How can one get the layer objects that correspond to a given group? It's easy to get layer IDs, it's not clear how to access the layer object even if one knows its ID. The gimp.image.layers sequence only contains the first-level layers and layer groups, not all the layers. In our document, all layers belong to a group, so that sequence only contains layer groups. When getting the children of a given group, pdb.gimp_item_get_children(group)[1] returns a tuple of IDs. Having only each layer's ID and not the layer object means one can't, for instance, make a new layer as a duplicate of an existing one. This code fails with a type error: newlayer = pdb.gimp_layer_new_from_drawable(layerID, image) Is there something I'm missing/doing wrong, or is this a gap in the available script-fu methods? Thanks, Javier Candeira. ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer