Adding custom properties or metadata to Layers?

Is it possible to add user-defined data to layers, in the same way that you might add a custom attribute to a node in Maya? For example, for me to add a new string property to a layer that I would access with app.activeDocument.layers[0].myProperty?

I don’t know of a way of directly customizing layer data and as far as I know from the Photoshop file spec there are no hooks in the layer data to accommodate custom data. That said there is support for arbitrary metadata on the document level and so you could add per-layer data by storing/accessing it by e.g. layer ID (obviously you’d have to come up with a way of handling layer merging and duplication etc.). There is a lengthy thread about accessing document metadata here: Document XMP metadata

thanks for the reply. Its good to know that there is metadata on the document level which can be edited.

The docs say that IDs are only relevant for the current photoshop session’s lifetime, so it might not be possible to save layer-specific data that is valid across multiple sessions (haven’t tested this myself yet).

Document ID is temporary. Layer ID is saved within document and persistent.

Document can have XMP metadata and every layer can have its own XMP metadata too. In addition layer can have “generator” metadata.

If you write code as in your example it will be added only to this one specific layer instance and it might or might not be available once you get that instance again. If next instance will be taken from internal cache then it could stay there within scope of your plugin until the plugin is reloaded. So rather don’t do that.

Additionally, you can add your own properties like this: https://developer.adobe.com/photoshop/uxp/2022/ps_reference/media/prototype/

1 Like

Would you mind pointing me to that section in the docs? :blush: In my experience so far (definitely with extendScript and it seems like with UXP as well) they stay persistent and get saved with the document (according to the file spec) under resource ‘lyid’. In fact what I’ve been describing to you is something that we do in our pipeline.

@Jarda, the properties added to prototypes aren’t saved with the document, are they?

That is correct they are not

Take a look on the following threads: