Adjust exposure of an ArtLayer

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

ruudw
Posts: 1
Joined: Fri Oct 19, 2018 11:05 am

Adjust exposure of an ArtLayer

Post by ruudw »

I am trying to adjust exposure of a newly created ArtLayer. I have tried three different approaches, but none really worked (see below). How should I do this?

What I have tried:
  1. Change exposure using a method on the ArtLayer. I thought to try adjustExposure, like adjustLevels. But such a function does not exist according to the documentation (and indeed raises an exception.

    Code: Select all

    docRef.activeLayer.adjustExposure(1, 0, 1);
  2. I tried creating an ArtLayer and change the kind to LayerKind.EXPOSURE. This raises an exception saying I'm only allowed to change type of an ArtLayer to text or normal
  3. Finally I tried duplicating an existing ArtLayer of kind exposure from an another document. Drawback would be I'd always require this file to be opened. But this has some weird effects because I'm looping through 3 channels and copy a layer 3 times. The script doesn't select the layers that I think it should, probably some reference problem. I've added this code below as a reference.

Code of my thrid option, that has weird effects:

Code: Select all


var adjustmentLayersRef = app.documents.getByName('adjustmentlayers.psd');
var docRef = app.activeDocument;

// Select last two channels
for (var i = 0; i < 2; i++) {
var layerRef = docRef.artLayers.add();
docRef.activeLayer = layerRef;

// Must activate source to copy layers from there
app.activeDocument = adjustmentLayersRef;

// Copy exposure layer
var adjustmentLayer = adjustmentLayersRef.layers[0].duplicate(docRef.activeLayer, ElementPlacement.PLACEBEFORE);
app.activeDocument = docRef;

adjustmentLayer.name = layerRef.name + ' adjustment ' + i;
adjustmentLayer.grouped = true;

// Restore the document we where editing
app.activeDocument = docRef;
}

Screenshots of what happens below:
Incorrect: When layer[0] is of kind "exposure" eveything goes wrong. No error messages, but the layers aren't copied to the target file and the rest of the process goes wrong...
Correct: When layer[0] is of kind "brightness" everything looks fine; target file receives two adjustment layers, each grouped above a single new layer.
copy-layers.png
copy-layers.png (95.93 KiB) Viewed 7856 times
User avatar
Stephen_A_Marsh
Posts: 29
Joined: Sun Aug 04, 2019 12:37 pm

Re: Adjust exposure of an ArtLayer

Post by Stephen_A_Marsh »

To create a new Exposure adjustment layer:

Code: Select all

// Script Listener recording processed via Clean SL
// Example: Exposure: 1, Offset: 0.25, Gamma Correction: 0.5
make(1, 0.25, 0.5);
function make(exposure, offset, gammaCorrection) {
	var c2t = function (s) {
		return app.charIDToTypeID(s);
	};

	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};

	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();
	var descriptor3 = new ActionDescriptor();
	var reference = new ActionReference();

	reference.putClass( s2t( "adjustmentLayer" ));
	descriptor.putReference( c2t( "null" ), reference );
	descriptor3.putEnumerated( s2t( "presetKind" ), s2t( "presetKindType" ), s2t( "presetKindDefault" ));
	descriptor3.putDouble( s2t( "exposure" ), exposure );
	descriptor3.putDouble( s2t( "offset" ), offset );
	descriptor3.putDouble( s2t( "gammaCorrection" ), gammaCorrection );
	descriptor2.putObject( s2t( "type" ), s2t( "exposure" ), descriptor3 );
	descriptor.putObject( s2t( "using" ), s2t( "adjustmentLayer" ), descriptor2 );
	executeAction( s2t( "make" ), descriptor, DialogModes.NO );
}