Slider not responding to value

Hey!
I’m trying to create a slider for some adjustments, passing the values to the function parameters using batchPlay, however, I don’t know how to make it work correctly when sliding return to the left.
In extendScript use doc.activeHistoryState = currentStatus; at the start of the function.
All help is appreciated

html

<sp-slider id="ajustRed" size="s"  min="-100" max="100" value="0" style="width: 160px;"> <sp-label slot="label">Vermelho</sp-label> </sp-slider>

js

document.querySelector("#ajustRed").addEventListener("change", async (func) => {
   await core.executeAsModal(async () => {ajustRed(func.target.value);})
})

async function ajustRed(valor){
   await app.batchPlay([{"_obj":"colorBalance","highlightLevels":[0,0,0],"midtoneLevels":[valor,0,0],"preserveLuminosity":true,"shadowLevels":[0,0,0]}],{});
}

Can anyone show me how a slider works in UXP?

Did you try searching the forum?

@Karmalakas, I searched everything in this forum, I found everything about slide except what I really need.
See the video that works partially, but does not work as it should.
What am I doing wrong?

here is my code
html

<sp-slider id="ajRed" size="s"  min="-100" max="100" value="0" style="width: 160px;"> <sp-label slot="label">Ajuste Red</sp-label> </sp-slider>
<sp-slider id="ajBlur" size="s"  min="0" max="100" value="0" style="width: 160px;"> <sp-label slot="label">Gaussian blur</sp-label> </sp-slider>

js

document.querySelector("#ajRed").addEventListener("change", async (func) => {
   await core.executeAsModal(async () => {ajustRed(func.target.value);})
}) 

document.querySelector("#ajBlur").addEventListener("change", async (func) => {
	await core.executeAsModal(async () => {ajustGBlur(func.target.value);})
 }) 

async function ajustRed(valor){
     await app.batchPlay([{"_obj":"colorBalance","midtoneLevels":[valor,0,0]}],{});
}

async function ajustGBlur(valor){
    await app.batchPlay([{"_obj":"gaussianBlur","radius":{"_unit":"pixelsUnit","_value":valor}}],{});
}

Based on what I see, you’re applying blur on a blur. I don’t think you can unblur the blur. What I mean, is you blur the pixels with value 75 for example and then reduce slider to 25 - that still blurs the pixels which are already blurred. I guess you’d need to convert layer to smart object first and then change blur value, so you could reduce blur after the fact

1 Like

Great solution, at first it works well, but for it to work 100%, I’ll have to add an if/else, because this only works if the blur effect is already applied to the layer, do you agree? Would you know the correct syntax to check if a smart object has a specific effect applied? Like a blur? Thanks for the support, when I grow up I want to be just like you.

Here you go, this code will check if select layer is smart object and which filter is applied to it. You should use Alchemist Plugin it will save you a lot of time.

 const batchPlay = require("photoshop").action.batchPlay;
    const layerKind = app.activeDocument.layers[0].kind;
    if (layerKind === "smartObject") {

      const result = await batchPlay(
        [
          {
            _obj: "get",
            _target: [
              {
                _property: "smartObjectMore",
              },
              {
                _ref: "layer",
                _id: app.activeDocument.activeLayers[0]._id,
              },
              {
                _ref: "document",
                _id: app.activeDocument?.id,
              },
            ],
            _options: {
              dialogOptions: "dontDisplay",
            },
          },
        ],
        {}
      );

      const pinned = result[0].smartObjectMore.filterFX.filterFXList[0];
      console.log(pinned.filter);
    } else {
      // select layer is not a smart object
      require("photoshop").core.showAlert(
        "Please make sure the slected layer is a smart object"
      );
    }
1 Like

@Wanokuni Thanks for the code! Taking the opportunity, would you know how to get the value of filterFX?

Use the code I wrote above with the Dev Tool to view the available parameters.

  const pinned = result[0].smartObjectMore.filterFX.filterFXList[0];
  const filterValue = pinned.filter.radius._value;
  console.log(pinned.filter);
 console.log("Filter value", filterValue);
1 Like

@Wanokuni Thank you for providing me with this precious information.