bringToFront (working with Folders)

Any solutions to this, I’ve tied using the

layer.bringToFront();

The info is void on:
https://www.adobe.io/photoshop/uxp/2022/ps_reference/classes/layer/#bringtofront

Also, tried using batchPlay and it isn’t working using what Alchemist provides.

this should work in batch play, you’d have to wrap the function in executeAsModal for API 2

const result = await batchPlay(
[
   {
      _obj: "move",
      _target: [
         {
            _ref: "layer",
            _enum: "ordinal",
            _value: "targetEnum"
         }
      ],
      to: {
         _ref: "layer",
         _enum: "ordinal",
         _value: "front"
      },
   }
],{
   synchronousExecution: false,
});

For some reason I can not get this to work with folders! It selects the two folders and halts, I also don’t get any issues in the debug

{
         "_obj": "select",
         "_target": [
            {
               "_ref": "layer",
               "_name": "Color"
            }
         ],
         "makeVisible": false,
         "layerID": [
            434
         ],
         "_isCommand": false
      },
      {
         "_obj": "select",
         "_target": [
            {
               "_ref": "layer",
               "_name": "Color"
            }
         ],
         "makeVisible": false,
         "layerID": [
            434
         ],
         "_isCommand": true
      },
      {
         "_obj": "select",
         "_target": [
            {
               "_ref": "layer",
               "_name": "Ambient"
            }
         ],
         "selectionModifier": {
            "_enum": "selectionModifierType",
            "_value": "addToSelectionContinuous"
         },
         "makeVisible": false,
         "layerID": [
            431,
            434
         ],
         "_isCommand": false
      },
      {
         "_obj": "select",
         "_target": [
            {
               "_ref": "layer",
               "_name": "Ambient"
            }
         ],
         "selectionModifier": {
            "_enum": "selectionModifierType",
            "_value": "addToSelectionContinuous"
         },
         "makeVisible": false,
         "layerID": [
            431,
            434
         ],
         "_isCommand": true
      },

      {
         "_obj": "move",
         "_target": [
            {
               "_ref": "layer",
               "_enum": "ordinal",
               "_value": "targetEnum"
            }
         ],
         "to": {
            "_ref": "layer",
            "_enum": "ordinal",
            "_value": "front"
         },
      },


   ], { synchronousExecution: false, })

}

Ok, when I hit the button twice, the second time it will place the folder on top. What does that mean?

This will select the layers called “Color” and “Ambient”, then move them to the top. If you change the select object to the folder name, it’ll select the folder.

const result = await batchPlay(
[
{
_obj: “select”,
_target: [
{
_ref: “layer”,
_name: “Color”
}
],
},
{
_obj: “select”,
_target: [
{
_ref: “layer”,
_name: “Ambient”
}
],
selectionModifier: {
_enum: “selectionModifierType”,
_value: “addToSelection”
},
},
{
_obj: “move”,
_target: [
{
_ref: “layer”,
_enum: “ordinal”,
_value: “targetEnum”
}
],
to: {
_ref: “layer”,
_enum: “ordinal”,
_value: “front”
},
}
],{
synchronousExecution: false,
});

Those are the folder names /shrug. There aren’t any layers with those names.

Is this what you’re referring to? The name is the folder and not a layer. It selects the folders and then pauses.

{
_obj: “select”,
_target: [
{
_ref: “layer”,
_name: “FOLDER NAME”
}

As far as I can tell, photoshop treats the selection of folders as layers.

If you have a folder called “Group01”, then change the selection name to “Group01”

{
_ref: “layer”,
_name: “Group01”
}

I don’t have an issue selecting, as the folders highlight and then nothing happens.

If I run the code once more, then one of the folders move to the top.

If you record the steps in alchemist yourself, does the folder move as expected if you just play the steps back?

The above code works as expected for me on multiple plugins, OS etc

Read this, could be an issue with the OS

Thanks man, I think there is a bug and will have to break it up, I ended up making a work around, but still want to get this to work… That said, I got sidetracked in another area of the plugin, I’ll circle back and update you!