How do I write a script to apply NON LEGACY AdjustBrightnessContrast(). Currently AdjustBrightnessContrast() uses legacy version.

  • 1
  • Question
  • Updated 3 years ago
Writing a script to apply NON LEGACY AdjustBrightnessContrast()
Photo of Wilfrid Ngo

Wilfrid Ngo

  • 5 Posts
  • 0 Reply Likes

Posted 3 years ago

  • 1
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 818 Reply Likes
You would need to include the descriptor for the legacy checkbox, and set it to false.
Without that descriptor, the code has to assume that you want the legacy behavior.  To get non-legacy behavior, you have to include the descriptor to say it is non-legacy.
Photo of Wilfrid Ngo

Wilfrid Ngo

  • 5 Posts
  • 0 Reply Likes
Thanks again, Chris. I guess I'm not too familiar with how that is done. I'm fairly new to all this. Can you possibly provide an example? 

Currently, I'm coding this up in Python. My code looks something like this:

import win32com.client
psApp = win32com.client.Dispatch("Photoshop.Application")

doc = psApp.Application.ActiveDocument

doc.ArtLayers[0].Duplicate()
doc.ArtLayers[0].AdjustBrightnessContrast(20,0)  # Bright +20, Contrast 0

I'm not sure how to add the descriptor to this

Many thanks!
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 818 Reply Likes
You have to build and use the descriptor directly instead of using the old convenience command for Brightness & Contrast.
Photo of Wilfrid Ngo

Wilfrid Ngo

  • 5 Posts
  • 0 Reply Likes
something like this but in python?

var idBrgC = charIDToTypeID( "BrgC" );    var desc6 = new ActionDescriptor();
    var idBrgh = charIDToTypeID( "Brgh" );
    desc6.putInteger( idBrgh, 20 );
    var idCntr = charIDToTypeID( "Cntr" );
    desc6.putInteger( idCntr, 0 );
    var iduseLegacy = stringIDToTypeID( "useLegacy" );
    desc6.putBoolean( iduseLegacy, false );
executeAction( idBrgC, desc6, DialogModes.NO );
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 818 Reply Likes
I hope you mean JavaScript, since Photoshop doesn't know anything about Python....

And yes, that looks about right.
Photo of Wilfrid Ngo

Wilfrid Ngo

  • 5 Posts
  • 0 Reply Likes
Solved it. If anybody is interested here is the solution in python:

import comtypes.client
objApp = comtypes.client.CreateObject("Photoshop.Application")

# Use dialog mode 3 for show no dialogs
dialogMode = 3

def AdjustBrightnessContrast(bright, contrast):
idBrgC = objApp.CharIDToTypeID( "BrgC" )
desc48 = comtypes.client.CreateObject( "Photoshop.ActionDescriptor" )
idBrgh = objApp.CharIDToTypeID( "Brgh" )
desc48.PutInteger( idBrgh, bright )
idCntr = objApp.CharIDToTypeID( "Cntr" )
desc48.PutInteger( idCntr, contrast )
iduseLegacy = objApp.StringIDToTypeID( "useLegacy" )
desc48.PutBoolean( iduseLegacy, False )
objApp.ExecuteAction( idBrgC, desc48, dialogMode )
return;