# PSD Document, consistent UID?

**URL:** <https://forums.creativeclouddeveloper.com/t/psd-document-consistent-uid/3418>\
**Category:** UXP Plugin API\
**Created:** [August 1, 2021, 7:02am UTC](https://forums.creativeclouddeveloper.com/t/psd-document-consistent-uid/3418 "2021-08-01T07:02:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![edgar](https://avatars.discourse-cdn.com/v4/letter/e/b487fb/32.png) [@edgar](https://forums.creativeclouddeveloper.com/u/edgar)\
**Post date:** [August 1, 2021, 7:02am UTC](https://forums.creativeclouddeveloper.com/t/psd-document-consistent-uid/3418/1 "2021-08-01T07:02:16Z")

</div>

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.

Thank you!

---

<div class="post-metadata">

**Author:** ![simonhenke](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/simonhenke/32/957_2.png) [@simonhenke](https://forums.creativeclouddeveloper.com/u/simonhenke)\
**Post date:** [August 1, 2021, 3:59pm UTC](https://forums.creativeclouddeveloper.com/t/psd-document-consistent-uid/3418/2 "2021-08-01T15:59:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)\
**Post date:** [August 1, 2021, 10:32pm UTC](https://forums.creativeclouddeveloper.com/t/psd-document-consistent-uid/3418/3 "2021-08-01T22:32:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![edgar](https://avatars.discourse-cdn.com/v4/letter/e/b487fb/32.png) [@edgar](https://forums.creativeclouddeveloper.com/u/edgar)\
**Post date:** [August 2, 2021, 9:57am UTC](https://forums.creativeclouddeveloper.com/t/psd-document-consistent-uid/3418/4 "2021-08-02T09:57:01Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![edgar](https://avatars.discourse-cdn.com/v4/letter/e/b487fb/32.png) [@edgar](https://forums.creativeclouddeveloper.com/u/edgar)\
**Post date:** [August 2, 2021, 9:58am UTC](https://forums.creativeclouddeveloper.com/t/psd-document-consistent-uid/3418/5 "2021-08-02T09:58:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![simonhenke](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/simonhenke/32/957_2.png) [@simonhenke](https://forums.creativeclouddeveloper.com/u/simonhenke)\
**Post date:** [August 2, 2021, 10:25am UTC](https://forums.creativeclouddeveloper.com/t/psd-document-consistent-uid/3418/6 "2021-08-02T10:25:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![edgar](https://avatars.discourse-cdn.com/v4/letter/e/b487fb/32.png) [@edgar](https://forums.creativeclouddeveloper.com/u/edgar)\
**Post date:** [August 4, 2021, 12:00pm UTC](https://forums.creativeclouddeveloper.com/t/psd-document-consistent-uid/3418/7 "2021-08-04T12:00:44Z")

</div>

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?
