# Unable to change BitDepth of a Document

**URL:** https://forums.creativeclouddeveloper.com/t/unable-to-change-bitdepth-of-a-document/5536
**Category:** UXP Plugin API
**Tags:** javascript
**Created:** [December 1, 2022, 12:23am UTC](https://forums.creativeclouddeveloper.com/t/unable-to-change-bitdepth-of-a-document/5536 "2022-12-01T00:23:11Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![photonic](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/photonic/32/2513_2.png) [@photonic](https://forums.creativeclouddeveloper.com/u/photonic)
#### Post date: [December 1, 2022, 12:23am UTC](https://forums.creativeclouddeveloper.com/t/unable-to-change-bitdepth-of-a-document/5536/1 "2022-12-01T00:23:11Z")

</div>

I made a simple function to know if the app.activeDocument has a 32Bit depth.

```auto
checkIfDocIs32Bit();
function checkIfDocIs32Bit() {
  app.activeDocument.bitsPerChannel = BitsPerChannelType.THIRTYTWO;
  console.log(app.activeDocument.bitsPerChannel);
}

```

This consoles.log this result:  
**bitDepth8**

Which I’m confused because as I read the Photoshop UXP API, the **app.activeDocument.bitsPerChannel** should console.log me **BitsPerChannelType.EIGHT** right?

So if I try to change the bitsPerChannel of my document I use this code:

```auto
app.activeDocument.bitsPerChannel = BitsPerChannelType.THIRTYTWO

```

But this gives me this error:  
**ReferenceError: BitsPerChannelType is not defined at checkIfDocIs32Bit**

What am I doing wrong?

---

<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: [December 1, 2022, 6:49am UTC](https://forums.creativeclouddeveloper.com/t/unable-to-change-bitdepth-of-a-document/5536/2 "2022-12-01T06:49:33Z")

</div>

You need to use `constants`  
Check this topic and the solution

> [@How do I use Constants in uxp?](http://forums.creativeclouddeveloper.com/t/how-do-i-use-constants-in-uxp/4019):
>
> As stated in the title。 require('photoshop').app.activeDocument.layers.forEach((layer) =\> { console.log(layer) if (layer.kind === LayerKind.TEXT) { console.log('文本图层') } }) But an error is reported Uncaught ReferenceError: LayerKind is not defined What did I miss? Thank you~

---

<div class="post-metadata">

### Author: ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)
#### Post date: [December 1, 2022, 4:21pm UTC](https://forums.creativeclouddeveloper.com/t/unable-to-change-bitdepth-of-a-document/5536/3 "2022-12-01T16:21:29Z")

</div>

Yes, these constants have to be imported in first place.

---

<div class="post-metadata">

### Author: ![photonic](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/photonic/32/2513_2.png) [@photonic](https://forums.creativeclouddeveloper.com/u/photonic)
#### Post date: [December 1, 2022, 5:17pm UTC](https://forums.creativeclouddeveloper.com/t/unable-to-change-bitdepth-of-a-document/5536/4 "2022-12-01T17:17:13Z")

</div>

Thank you very much for your answer @Karmalakas !

---

<div class="post-metadata">

### Author: ![photonic](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/photonic/32/2513_2.png) [@photonic](https://forums.creativeclouddeveloper.com/u/photonic)
#### Post date: [December 1, 2022, 5:21pm UTC](https://forums.creativeclouddeveloper.com/t/unable-to-change-bitdepth-of-a-document/5536/5 "2022-12-01T17:21:32Z")

</div>

Thank you very much @Jarda ! This worked well! I tried to find where in the documentation mentions about imprting these constants but seems I cannot find that in the documentation. This would be helpful to know for people who read the docs.

---

<div class="post-metadata">

### Author: ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)
#### Post date: [December 1, 2022, 9:51pm UTC](https://forums.creativeclouddeveloper.com/t/unable-to-change-bitdepth-of-a-document/5536/6 "2022-12-01T21:51:16Z")

</div>

I agree. But this applies for all constants so you would repeat that mention like 300-100× so we have to find a smart way to make sure all devs will see it when need it but don’t bloat documentation with repetitive information 🤔

Any ideas? 🙂

---

<div class="post-metadata">

### Author: ![photonic](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/photonic/32/2513_2.png) [@photonic](https://forums.creativeclouddeveloper.com/u/photonic)
#### Post date: [December 1, 2022, 10:54pm UTC](https://forums.creativeclouddeveloper.com/t/unable-to-change-bitdepth-of-a-document/5536/7 "2022-12-01T22:54:34Z")

</div>

When I read your comment I tried to figure out a way to make a better UX for us as developers, what about writing a simple code example to import those constants on the top of the Constants page? That would be very helpful as there are all the constants but it doesn’t mention how to use them / import them.

 ![Screenshot 2022-12-01 164747](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/a/a3ff15acdb875bbb0e2161dd9a5712e0338e56e0.png)

Also I was thinking about to add a library that could load automatically when creating a plugin from the UXP developer tools and inside that library would be contained all those constants but in a global way.

The problem here is that If we call a function to load them they would live inside the function but not outside as a global constant, so I’m thinking more ways how this could be improved.

In the meantime I think adding this little code example to import constants on the Constants page would help a lot to guide us.

---

<div class="post-metadata">

### Author: ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)
#### Post date: [December 2, 2022, 12:14am UTC](https://forums.creativeclouddeveloper.com/t/unable-to-change-bitdepth-of-a-document/5536/8 "2022-12-02T00:14:01Z")

</div>

Yes, it should be there for sure. But it might not be enough 🙂

---

<div class="post-metadata">

### Author: ![photonic](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/photonic/32/2513_2.png) [@photonic](https://forums.creativeclouddeveloper.com/u/photonic)
#### Post date: [December 2, 2022, 1:56am UTC](https://forums.creativeclouddeveloper.com/t/unable-to-change-bitdepth-of-a-document/5536/9 "2022-12-02T01:56:38Z")

</div>

I agree! I’ll think about other ways how this could be easier, thank you Jarda!
