# Setting minimum brush opacity

**URL:** <https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104>\
**Category:** UXP Plugin API\
**Created:** [June 16, 2021, 5:11pm UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104 "2021-06-16T17:11:24Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndreasResch](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/andreasresch/32/1423_2.png) [@AndreasResch](https://forums.creativeclouddeveloper.com/u/AndreasResch)\
**Post date:** [June 16, 2021, 5:11pm UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/1 "2021-06-16T17:11:24Z")

</div>

Hello.

Does anybody know the code to set the minimum brush opacity. I was able to get the “get” code from Alchemist, but can’t figure out how to convert it to a “set” code.

Here’s the “get” code …

```auto
const batchPlay = require("photoshop").action.batchPlay;
const result = await batchPlay(
[
   {
      "_obj": "get",
      "_target": [
         {
            "_property": "currentToolOptions"
         },
         {
            "_ref": "application",
            "_enum": "ordinal",
            "_value": "targetEnum"
         }
      ],
      "_options": {
         "dialogOptions": "dontDisplay"
      }
   }
],{
   "synchronousExecution": false,
   "modalBehavior": "fail"
});
const pinned = result[0].currentToolOptions.$opVr.minimum;

```

---

<div class="post-metadata">

**Author:** ![AndreasResch](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/andreasresch/32/1423_2.png) [@AndreasResch](https://forums.creativeclouddeveloper.com/u/AndreasResch)\
**Post date:** [June 22, 2021, 6:13pm UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/2 "2021-06-22T18:13:03Z")

</div>

Anybody? Maybe @kerrishotts ?

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [June 22, 2021, 6:55pm UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/3 "2021-06-22T18:55:57Z")

</div>

I so feel you 🙂  
We really need the docs for all these `_obj`, `_target._ref`, `_target._property` and so on…  
Currently BatchPlay is a guessing game a lot of the time

---

<div class="post-metadata">

**Author:** ![simonhenke](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/simonhenke/32/957_2.png) [@simonhenke](https://forums.creativeclouddeveloper.com/u/simonhenke)\
**Post date:** [June 22, 2021, 10:44pm UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/4 "2021-06-22T22:44:24Z")

</div>

I figured it out…

```auto
const toolOpt: PaintBrushToolOptionsDescriptor = getAppProperty('currentToolOptions') as PaintBrushToolOptionsDescriptor
  toolOpt.$opVr.minimum._value = 50
  const desc = {
    _obj: 'set',
    _target: {
      _ref: [{ _ref: 'paintbrushTool'}],
    },
    to: toolOpt
  }

  photoshop.action.batchPlay([desc], {})

```

3 Notes:

- You can ignore the types if you’re not using typescript, although I highly recommend it to know what’s going on inside the descriptors.
- For a different tool type, you might need to change the class reference (`paintbrushTool`). Might be possible to dynamically read that, too.
- If no opacity control is selected, you’ll have to set one first, too:  
`toolOpt.$opVr.$bVTy = 1` (0: off, 1: fade, 2: pen pressure, etc.)

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [June 23, 2021, 6:26am UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/5 "2021-06-23T06:26:40Z")

</div>

> [@simonhenke](#):
>
> You can ignore the types if you’re not using typescript, although I highly recommend it to know what’s going on inside the descriptors

I tried to set it up some time ago on PHP Storm, but didn’t succeed. Maybe I’ll try again one day 🤔

---

<div class="post-metadata">

**Author:** ![AndreasResch](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/andreasresch/32/1423_2.png) [@AndreasResch](https://forums.creativeclouddeveloper.com/u/AndreasResch)\
**Post date:** [June 23, 2021, 8:09am UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/6 "2021-06-23T08:09:17Z")

</div>

Thanks for the tsuggestion. However I get an “Missing initializer in const declaration” error in the const definition line. And as I can’t find a place to look that up, could you please enlighten me a bit more. I can’t even find anything about “getAppProperty”.

Where did you get those information from? Even Google delivers no result when I search for “PaintBrushToolOptionsDescriptor”.

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [June 23, 2021, 8:59am UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/7 "2021-06-23T08:59:40Z")

</div>

`getAppProperty` is your initial getter code without the last part of `.$opVr.minimum`

```auto
const pinned = result[0].currentToolOptions;

```

Then first line basically becomes this:

```auto
const toolOpt = pinned;

```

Everything else should be good I think.

---

<div class="post-metadata">

**Author:** ![AndreasResch](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/andreasresch/32/1423_2.png) [@AndreasResch](https://forums.creativeclouddeveloper.com/u/AndreasResch)\
**Post date:** [June 23, 2021, 9:11am UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/8 "2021-06-23T09:11:52Z")

</div>

So “getAppProperty” is a function that I have to declare myself?

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [June 23, 2021, 9:16am UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/9 "2021-06-23T09:16:48Z")

</div>

At least that’s what I did in my plugin following Simons advice in the other topic 🙂

---

<div class="post-metadata">

**Author:** ![simonhenke](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/simonhenke/32/957_2.png) [@simonhenke](https://forums.creativeclouddeveloper.com/u/simonhenke)\
**Post date:** [June 23, 2021, 11:41am UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/10 "2021-06-23T11:41:43Z")

</div>

@Karmalakas is right 🙂 The code I post isn’t always for direct copy/paste. I try to show the relevant parts to understand the concept. So sometimes it might include some getters or helpers, which aren’t directly part of the solution or can be easily replicated. As @Karmalakas pointed out, you already had a function to get the app property, so I just left that in there. Just in case, I’ll post it here, too:

```auto
function getAppProperty<T extends keyof ApplicationDescriptor>(_property: T): ApplicationDescriptor[T] {
  return photoshop.action.batchPlay([
    {
      _obj: 'get',
      _target: [{ _property}, { _ref: 'application', _enum: 'ordinal', _value: 'targetEnum' }],
    },
  ], { synchronousExecution: true })[0][_property]
}

```

(the types can be removed again, I’m just too lazy when pasting it here 😅)

`PaintBrushToolOptionsDescriptor` is just the name I gave to [that type](https://github.com/simonhenke/photoshop-types/blob/main/types/Tool.d.ts#L418), but you could also just leave it out and write  
`const toolOpt = getAppProperty('currentToolOptions')`. It’s just helping me to not make any mistakes while navigating through those nested objects. For example if you’d forget that `minimum` is not a number, but a percent value, you’d get the following error:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/d/d9d81bcd21582d1956b52a353e835ab3eae076ae.png)

---

<div class="post-metadata">

**Author:** ![AndreasResch](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/andreasresch/32/1423_2.png) [@AndreasResch](https://forums.creativeclouddeveloper.com/u/AndreasResch)\
**Post date:** [June 23, 2021, 11:52am UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/11 "2021-06-23T11:52:33Z")

</div>

Cheers. I’ll give it a try.

---

<div class="post-metadata">

**Author:** ![simonhenke](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/simonhenke/32/957_2.png) [@simonhenke](https://forums.creativeclouddeveloper.com/u/simonhenke)\
**Post date:** [June 23, 2021, 11:55am UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/12 "2021-06-23T11:55:53Z")

</div>

And I also didn’t have any place to look that up. As @Karmalakas said, batchPlay is a guessing game with a lot of trial and error.

The syntax for setting properties is always quite similar. Something like

```auto
{
    _obj: 'set',
    _target: ...,
    to: ...
}

```

The tricky part is that you don’t always know what to set it to. Some setters allow you to set just a subset (for example just setting the font size of a textLayer) of the property that you want to update. But to be on the safe side, you can also just get the full property, change a value and then set the whole property.

The `target` also has some varying syntax… I also didn’t fully understand the pattern yet, but there are essentially two ways of targeting things.

---

<div class="post-metadata">

**Author:** ![assitburn](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/assitburn/32/1499_2.png) [@assitburn](https://forums.creativeclouddeveloper.com/u/assitburn)\
**Post date:** [June 24, 2021, 6:39am UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/13 "2021-06-24T06:39:01Z")

</div>

Hi @all.

I have tried to use the code you have provided here, but I am not clever enough 😉

If someone would provide a complete function to set the opacity I would be deeply grateful.

---

<div class="post-metadata">

**Author:** ![AndreasResch](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/andreasresch/32/1423_2.png) [@AndreasResch](https://forums.creativeclouddeveloper.com/u/AndreasResch)\
**Post date:** [June 24, 2021, 9:16am UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/14 "2021-06-24T09:16:50Z")

</div>

After a lot of trial and error and taking bits from Alchemist and Simon’s suggestions , I got it to work. This is tricky as hell. It’s obvious that this part needs documentation in some form.

Here’s the complete code …

```auto
const batchPlay = require("photoshop").action.batchPlay;

// GET TOOL OPTIONS
async function getCurrentToolOptions () {
  const result = await batchPlay(
  [
     {
        "_obj": "get",
        "_target": [
           {
              "_property": "currentToolOptions"
           },
           {
              "_ref": "application",
              "_enum": "ordinal",
              "_value": "targetEnum"
           }
        ],
        "_options": {
           "dialogOptions": "dontDisplay"
        }
     }
  ],{
     "synchronousExecution": false
  });
  return result[0].currentToolOptions;
}

// SET TOOL OPTIONS
async function setCurrentToolOptions(currenttooloptions) {
  const result = await batchPlay(
  [
     {
        "_obj": "set",
        "_target": [
           {
             "_ref": "paintbrushTool"
           }
        ],
        "to": currenttooloptions
     }
  ],{
     "synchronousExecution": false
  });
}

async function test1() {
  let cto = await getCurrentToolOptions();
  cto.$opVr.minimum._value = 20;
  await setCurrentToolOptions(cto);
}

document.getElementById("test1").addEventListener("click", test1);

```

---

<div class="post-metadata">

**Author:** ![AndreasResch](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/andreasresch/32/1423_2.png) [@AndreasResch](https://forums.creativeclouddeveloper.com/u/AndreasResch)\
**Post date:** [June 24, 2021, 9:17am UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/15 "2021-06-24T09:17:18Z")

</div>

Thanks for all the help, Simon. Much appreciated.

---

<div class="post-metadata">

**Author:** ![AndreasResch](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/andreasresch/32/1423_2.png) [@AndreasResch](https://forums.creativeclouddeveloper.com/u/AndreasResch)\
**Post date:** [June 24, 2021, 11:27am UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/16 "2021-06-24T11:27:39Z")

</div>

The next step would be to listen to the event of changing brush settings (like brush size, opacity etc.) so I can synchronize my panel with the Photoshop settings. Otherwise this would be chaos.

I tried “eventNotifier” but most brush-related events are not showing up there. What would be the proper method to achieve that?

---

<div class="post-metadata">

**Author:** ![assitburn](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/assitburn/32/1499_2.png) [@assitburn](https://forums.creativeclouddeveloper.com/u/assitburn)\
**Post date:** [June 24, 2021, 2:28pm UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/17 "2021-06-24T14:28:04Z")

</div>

It is still not working. if I click the button. (brush is activated) nothing happens.

I have checked. both functions are called and able to make an alert-output.  
But the opacity did not change.

Any idea?

---

<div class="post-metadata">

**Author:** ![AndreasResch](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/andreasresch/32/1423_2.png) [@AndreasResch](https://forums.creativeclouddeveloper.com/u/AndreasResch)\
**Post date:** [June 24, 2021, 6:12pm UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/18 "2021-06-24T18:12:49Z")

</div>

This one changes the “Minimum Opacity”. And here it works. The value was 0 before the click.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/c/c15ae041655b9be69f6f0275b21827d050b47c98.png)

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [June 24, 2021, 6:24pm UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/19 "2021-06-24T18:24:50Z")

</div>

Not sure if this can be related, but I can’t change the minimum value in Ps itself, so maybe that’s the case for you too @assitburn 🤔 When I change the slider, as soon as I click outside, it jumps right back to zero. Didn’t bother to figure out why to be honest 🙂

---

<div class="post-metadata">

**Author:** ![AndreasResch](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/andreasresch/32/1423_2.png) [@AndreasResch](https://forums.creativeclouddeveloper.com/u/AndreasResch)\
**Post date:** [June 24, 2021, 6:46pm UTC](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104/20 "2021-06-24T18:46:43Z")

</div>

That sounds weird and might be the cause of the issue. I guess this is a case for the general Photoshop support.

[Next page](https://forums.creativeclouddeveloper.com/t/setting-minimum-brush-opacity/3104.md?page=2)
