I am planning to refactor my old CEP extension panels to UXP.
I need to know and learn a lot of new stuff but my first thing to know is how can I store and retrive custom information (JSON, TEXT) in the .psd. I previously used XMP and additionally document’s .generatorSetting key via generator-core.js to store these. But as I see generator will be removed sooner or later so .setDocumentSettingsForPlugin() is not an option. I feel this XML and XMP a bit hard to implement with npm XML modules and batchPlay().
Is there a way to simply store/retrieve a string in/from the document within UXP’s reach?
As far as I know there aren’t any new hooks in the underlying Photoshop file that would allow custom data (at least not according to specs). So adding that through XMP is still your best option. There’s an existing thread about this that goes into implementation details: Document XMP metadata. At the core you’d use batchPlay to retrieve and set the XMP data do the document (I don’t think there’s an API function for that yet), you parse the corresponding XML. We are doing something very similar in our pipeline to embed custom data into the File, typically just a JSON dictionary that can be as complex as needs to be. In my experience most complexity can be wrapped in functions to set and retrieve so once you have these you don’t have to deal with XMP again… Another thing to be set about the XMP hook in the file is that it’s general and I find it relatively straight forward to retrieve outside of Photoshop (i.e. you don’t have to parse the file in all detail to get to the blob that contains the XMP data).
Then I have this way only. Tame the dinosaur and extend the document object with a setXMP( key, value ) and a getXMP( key ) methods. I have to watch the execution times, because the XMP is sometimes bloated with megabytes of unnecessary data. I suppose Indesign infesting the .psds which was linked into a storyboard document once.
One thing that I should clarify about what I said earlier: I had mentioned using a dictionary as the piece of information stored to and retrieved from XMP. This means rather than accessing XMP each and every time you want to set/get a key value pair you’d access XMP once when loading your file and once when saving. The rest of the time you only operate on your dict/object. So the thing you’d store in XMP would not be an atomic property but a JSON data blob and you could easily identify it in a way that allows you to ignore any other data. The JSON data can then be as complex as you need.