# Converting smart object to layers in UXP?

**URL:** <https://forums.creativeclouddeveloper.com/t/converting-smart-object-to-layers-in-uxp/7929>\
**Category:** UXP Plugin API\
**Created:** [May 27, 2024, 9:05pm UTC](https://forums.creativeclouddeveloper.com/t/converting-smart-object-to-layers-in-uxp/7929 "2024-05-27T21:05:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tim35050](https://avatars.discourse-cdn.com/v4/letter/t/ebca7d/32.png) [@tim35050](https://forums.creativeclouddeveloper.com/u/tim35050)\
**Post date:** [May 27, 2024, 9:05pm UTC](https://forums.creativeclouddeveloper.com/t/converting-smart-object-to-layers-in-uxp/7929/1 "2024-05-27T21:05:23Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![Ancelmoa](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/ancelmoa/32/3640_2.png) [@Ancelmoa](https://forums.creativeclouddeveloper.com/u/Ancelmoa)\
**Post date:** [May 28, 2024, 5:59pm UTC](https://forums.creativeclouddeveloper.com/t/converting-smart-object-to-layers-in-uxp/7929/2 "2024-05-28T17:59:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![YesserKira](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/yesserkira/32/3796_2.png) [@YesserKira](https://forums.creativeclouddeveloper.com/u/YesserKira)\
**Post date:** [May 28, 2024, 9:54pm UTC](https://forums.creativeclouddeveloper.com/t/converting-smart-object-to-layers-in-uxp/7929/3 "2024-05-28T21:54:24Z")

</div>

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.

 ![Screenshot 2024-05-28 224822](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/2/2aa173adaa1e1890921945a8794cfaedecb59181.png)

---

<div class="post-metadata">

**Author:** ![tim35050](https://avatars.discourse-cdn.com/v4/letter/t/ebca7d/32.png) [@tim35050](https://forums.creativeclouddeveloper.com/u/tim35050)\
**Post date:** [May 28, 2024, 10:14pm UTC](https://forums.creativeclouddeveloper.com/t/converting-smart-object-to-layers-in-uxp/7929/4 "2024-05-28T22:14:24Z")

</div>

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:

```auto
{
            _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](https://forums.creativeclouddeveloper.com/uploads/short-url/6xvWU08EFfNc6acdB5b73yngkSF.zip) (13.0 KB)

Thank you!

Best,  
Tim

---

<div class="post-metadata">

**Author:** ![tim35050](https://avatars.discourse-cdn.com/v4/letter/t/ebca7d/32.png) [@tim35050](https://forums.creativeclouddeveloper.com/u/tim35050)\
**Post date:** [May 28, 2024, 10:26pm UTC](https://forums.creativeclouddeveloper.com/t/converting-smart-object-to-layers-in-uxp/7929/5 "2024-05-28T22:26:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tim35050](https://avatars.discourse-cdn.com/v4/letter/t/ebca7d/32.png) [@tim35050](https://forums.creativeclouddeveloper.com/u/tim35050)\
**Post date:** [May 28, 2024, 10:27pm UTC](https://forums.creativeclouddeveloper.com/t/converting-smart-object-to-layers-in-uxp/7929/6 "2024-05-28T22:27:19Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![ahmedahres](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@ahmedahres](https://forums.creativeclouddeveloper.com/u/ahmedahres)\
**Post date:** [April 11, 2025, 1:15pm UTC](https://forums.creativeclouddeveloper.com/t/converting-smart-object-to-layers-in-uxp/7929/7 "2025-04-11T13:15:11Z")

</div>

Thanks for this! Did you get the issue: ‘operation “Convert To Layers” is not currently available’?
