It's gonna be hard to build xmp from scratch, as a plugin, me-thinks. As you've already noticed, the database is not accessible, except in very limited fashion via SDK. It may be worth considering extraction of xmp from jpg instead, or as a starting point, via exiftool, like xEmP does. I use keyboard injection to trigger xmp save, but that technique leaves a lot to be desired (doesn't work reliably). If you are hell-bent on doing it from scratch, I think you'd have to read the catalog upon startup, or an inactive catalog of the catalog after startup... Note: it would be easy to create xmp from a non-plugin app without Lightroom running, since the xmp is essentially there at the ready, not sure what issues there might be in assuring freshness...
Yeah, I have already used tools in the past that can easily and perfectly extract the XMP (exiv), but I guess I just really wished that feature was in Lightroom natively and I was hoping to implement it myself.
Thank you for the feedback!
Actually, one more request: could you please briefly explain how keyboard injection works as a Lightroom plugin? I am just curious. Thanks.
I mean, everything about the job is easy, *except* the database is locked, and SDK doesn't provide the requisite info. If you don't mind generating xmp upon startup, instead of during operation, it's cake. Generating fresh stuff while running however - don't see how else besides save-to-jpeg in Lightroom, followed by extraction using exiftool.
autohotkey in windows, applescript on mac.
Download xEmP (includes source code), and you can see how it's been done.
Note: Mac has become more of a problem lately - some systems don't allow on-the-fly execution of text scripts (and some do...). I really need to compile the applescript, assuming that would help - it's on my to-do list...
Funny coincidence, I just wrote a little XMP extractor plugin this afternoon, it's implemented as an export filter plugin. (It is going to be a part of a bigger plugin later on.)
I need it to extract developed XMP data, so I just use export original option and insert this plugin as a post-process action. If the original is TIF, JPEG, PSD, DNG then the XMP will be embedded and I then use exiftool to extract it. For other RAW files, LR exports XMP itself.
Btw, LR export is quite fast when exporting original images, because it does not need to actually render any pixels...
Plugin is available from http://www.capturemonkey.com/xmpextract in case you want to try that approach.
There's no source there, but it is basically just calling exiftool inside postProcessRenderedPhotos method, less than 20 effective lines anyway