Converting smart object to layers in UXP?

Hello! I have a smart object that I’d like to convert to layers in UXP. In Alchemist, selecting my smart object and clicking “Convert To Layers” generates the following:

const result = await batchPlay(
      [
         {
            _obj: "duplicate",
            _target: [
               {
                  _ref: "layer",
                  _name: ""
               },
               {
                  _ref: "layer",
                  _name: "shadow"
               },
               {
                  _ref: "layer",
                  _name: ""
               },
               {
                  _ref: "layer",
                  _name: "artwork"
               },
               {
                  _ref: "layer",
                  _name: "inner shadow"
               },
               {
                  _ref: "layer",
                  _name: "frame"
               },
               {
                  _ref: "layer",
                  _name: "adjustable frame"
               },
               {
                  _ref: "layer",
                  _name: "3x4 frame"
               }
            ],
            to: {
               _ref: "document",
               _name: "room.psd"
            },
            destinationDocumentID: 274,
            name: "3x4 frame",
            version: 5,
            ID: [
               602,
               603,
               604,
               605,
               606,
               607,
               608,
               609
            ],
            _options: {
               dialogOptions: "dontDisplay"
            }
       }
]

I am able to generate this exact object programmatically, but when I run it in batchplay, I get the error The command “Duplicate” is not currently available. I have tried selecting the smart object first, as well as inserting additional keys like layerID: { <the smart object’s ID> } but nothing seems to work.

The only other thing left to do is to open the smart object programmatically, copy the layers, close the smart object doc, and paste the layers, but there has to be a better way!

Thank you in advance for your guidance.

Best,
Tim

Could you make the file you want to convert into layers available?

To convert a smart object to a layer, you need to use the ‘Rasterize’ option.
For the code needed in your panel, you can record the necessary steps using an action and then use this option to copy the JavaScript of your action without needing a third-party plugin.

Thank you for your reply! Yes, I created a much simpler PSD where the issue still happens, and attached the PSD file here. The first layer is a group (Group 1), which you can right-click and convert to smart object, then right click again and “Convert to Layers” to “undo” that smart object creation. In Alchemist, you should be able to see that the “Convert to Layers” action looks like this:

{
            _obj: "duplicate",
            _target: [
               {
                  _ref: "layer",
                  _name: ""
               },
               {
                  _ref: "layer",
                  _name: "another layer"
               },
               {
                  _ref: "layer",
                  _name: "some layer"
               },
               {
                  _ref: "layer",
                  _name: "Group 1"
               }
            ],
            to: {
               _ref: "document",
               _name: "Untitled-1"
            },
            destinationDocumentID: 259,
            name: "Group 1",
            version: 5,
            ID: [
               59,
               60,
               61,
               62
            ],
            _options: {
               dialogOptions: "dontDisplay"
            }

Programmatically, I was able to generate the same object, but running it in batch play yields the error: The command “Duplicate” is not currently available.

convertToLayersHelp.psd.zip (13.0 KB)

Thank you!

Best,
Tim

WOW, that Copy as JavaScript trick is amazing! It revealed the ‘placedLayerConvertToLayers’ object, which works perfectly in Batch Play! Thank you so much for your help, this solves it!

Regarding ‘Rasterize’, that will flatten the smart object, which I definitely don’t want. I wanted the ability to take a group, convert it to smart object, then convert it back to the original group. You need ‘Convert to Layers’ to do that.

Best,
Tim

For others reading, here is the code you can run to Convert To Layers in UXP:

async function convertToLayers() {
    return await action.batchPlay([{
        _obj: "placedLayerConvertToLayers",
        _options: {
           dialogOptions: "dontDisplay"
        }
    }], {});
}
1 Like