Issues with .duplicate into a new doc

Hey friends, long time listener first time caller. I’m trying to update some old scripts to UXP for ease of use. I’m running into some issues with duplicating a layer to a new document.

async function exportLayer(){
  const app = require("photoshop").app;

  // Get the active document and store width and height as variables
  var originalDoc = app.activeDocument;
  var originalDocWidth = originalDoc.width;
  var originalDocHeight = originalDoc.height;

  var layerToCopy = originalDoc.activeLayers[0];

  // Create new doc same size as old one
  var newDoc = app.documents.add({
    width: originalDocWidth,
    height: originalDocHeight
  });

  var newLayer = await layerToCopy.duplicate(newDoc, ElementPlacement.PLACEATBEGINNING);
}

The new doc is created, no issues. If I remove the ‘newDoc, ElementPlacement.PLACEATBEGINNING’ from the .duplicate, it duplicates in the original document just fine. It just doesn’t want to copy to the new doc.

Is there a way to make this work without using batchPlay, or is that my next step?

Thanks so much for the help! Been banging my head against this new-to-me UXP stuff for a day or so.

I believe you are correct in that it is not present. I see layer.duplicate didn’t have a “New Document” option in ExtendScript either (which is mostly why you don’t see it yet for UXP).

Turns out it’s not a “duplicate” call but a “make”.

        // Make document
        {
            "_obj": "make",
            "_target": [ { "_ref": "document" } ],
            "name": "blah",
            "using": { "_enum": "ordinal", "_ref": "layer", "_value": "targetEnum"},
            "version": 5
        }

:information_source: Copy as JavaScript is what I used to get the above.
https://developer.adobe.com/photoshop/uxp/2022/ps_reference/media/batchplay/#accepted-action-descriptors

Thanks, mate. Is there any documentation on which aspects of the DOM are unavailable via UXP?

If you mean, “What in Ps is not doable via UXP DOM?”, that’s a difficult question. Ps is a big, complicated machine, and there isn’t a clear route to discern the answer. Right now, UXP DOM is meant to cover ExtendScript (with some caveats). ExtendScript never covered everything either, but it was the right first step.

There have been surveys and polls in the past to collect the most popular missing bits. I’d like to see a living list though: maybe the Docs section could be useful for that.

Not shipped in UXP DOM but exists in ExScript DOM

  • half of the selection features
  • priting and print settings
  • document metadata I believe
  • few pixel filters
  • some PS settings got obsolete and cannot be set anymore
    Did I forget something @DavideBarranca

UXP DOM has missing

  • everything related to smart objects
    • no smart filters and its options
    • can’t open smart object
  • everything related to layer effects
  • no gradients
  • no current tool settings
  • about 60 Photoshop preferences
  • no access to masks… pixel mask, vector mask, filter mask are all missing
  • everything related to artboard specific settings
  • only basic guides meaning no artboard guides,
    • no guide grid settings
    • no guide color settings
  • things I mentioned above available in ExScript DOM
  • it is missing like 60 PS preferences
  • no presets manager
  • maybe like 50+ missing filters?
  • you can’t adjust adjustment layers
  • you can’t adjust shape layers (almost)
  • no support for AI Firefly
  • no support for frame tool
  • no support for patterns or patterns layers
  • no video scripting
  • no 3D scripting
  • notes are also not in DOM
  • measurements are not in DOM
  • you can’t control zooming or panning
  • no support for document window or panel management
  • you can’t control option under View in PS main menu
  • symetry option for paths

To make it shorter. It has missing pretty much everything. It is much quicker and easy to learn what is supported because it is not that much.

I was thinking whether it would worth it to make crowdfunded open sourced PS DOM. In typescript so… up to date types would be easy and anyone could change it or fork it for their own needs.

2 Likes

Thanks Jarda. It’s been a frustrating learning curve just because I keep running into things that aren’t working as I’d expect them to, or just not working at all. Even if there was SOME debug support that would be helpful, rather than just exiting the function.

I’m ending up just converting everything to batchplay. Which, while a little less readable and more cumbersome is at least responding how I’d expect.

yes… everyone who wants to do something serious is doing something like that. Kind of making their own DOM version.

Maybe you could extend prototypes: https://developer.adobe.com/photoshop/uxp/2022/ps_reference/media/prototype/

Classes are exposed… you can instantiate new Layer() by layerID and docID.