Unable to change BitDepth of a Document

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

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:

app.activeDocument.bitsPerChannel = BitsPerChannelType.THIRTYTWO

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

What am I doing wrong?

You need to use constants
Check this topic and the solution

1 Like

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

1 Like

Thank you very much for your answer @Karmalakas !

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.

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 :thinking:

Any ideas? :slight_smile:

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.

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.

2 Likes

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

1 Like

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