I’m looking to save the metadata of all text layers and link the metadata with the document, so users may load previous versions of all text layers (e.g. switch between different languages). Now that I’ve realized that the id from app.activeDocument._id changes every time a file is opened, I’d like to know if there’s a unique and consistent id for each document. If the answer is no, I’ll have to use document title as the key, which could be quite messy since the name may change.
If it’s layer related information, maybe it would be even better to attach it to the layer instead, then you don’t have to worry about the document. You could use the XMPMetaData for that.
I think with newly started PS you get document ID 1. With every new history step/snapshot it increments 1 and new document is also +1. You should set your own UUID if none was made by your software in document before.
I did save info by layer id. The json file has this pattern: documentId–>languageCode–>layerId–>textKey&textStyleRange. The problem is that the documentId is always changing, and I need something that doesn’t change as the key. I did check the XMPMetaData, but it looks like a big chunk of scrambled text. Could you please be specific about the property I should look at?
I observed an increment of 4 each time a document is opened, but there’s no guaranteeing that the behavior will be consistent in all scenarios. It’s like having a database where the primary key is always changing…while you can only provide one key when adding an entry.
What I meant is that instead of storing the data inside a separate JSON file (referencing it by DocID>LanguageCode>LayerID - which doesn’t really work due to dynamic DocIDs), you could “attach” it directly on each Photoshop layer. Layers have a property called XMPMetaData which you can read/write, essentially it’s string based key/value data. It’s a bit complicated, but I’ve posted a working example on the forums here, if you search for XMPMetaData you should find it.
Thanks! I saw your code example, will definitely give a shot, should solve the data saving problem. Meanwhile, there’s a different scenario where a consistent document ID is ideal. The current plugin is powered by an MT engine, but our artists would like to export text content and get it translated by human translators, then adjust the design with the final multilingual copy. Is there a way to import translations without requiring the user to select a file? Maybe an identifier of some sort can be stored on export?