Skip to main content
Inspiring
June 10, 2020
Resuelto

Trying to create a Duplicate Layer with a new name

  • June 10, 2020
  • 2 respuestas
  • 755 visualizaciones

I have the following code;

 

	var docRef = activeDocument
	var newdLayer = docRef.activeLayer.duplicate();
	newdLayer;
	docRef.activeLayer = docRef.layers["Background copy"]
	docRef.activeLayer.applyGaussianBlur(20);


What I really want to do is create the new layer with the name BLUR because the original layer may not be the background

New to this and looking to learn

Mike

Este tema ha sido cerrado para respuestas.
Mejor respuesta de JJMack

Try duplicating the layer then name the new active layer.

newLayer =  somelayerobject.duplicate();

newLayer.name = "LayerName";

 

2 respuestas

c.pfaffenbichler
Community Expert
Community Expert
June 10, 2020

Or use AM-code: 

duplicateLayerAndName("blur");
////// duplicate a layer and name it //////
function duplicateLayerAndName (theName) {
var desc2 = new ActionDescriptor();
var desc3 = new ActionDescriptor();
desc3.putString( stringIDToTypeID( "name" ), theName );
desc2.putObject( stringIDToTypeID( "new" ), stringIDToTypeID( "layer" ), desc3 );
var idusing = stringIDToTypeID( "using" );
desc2.putEnumerated( idusing, stringIDToTypeID( "areaSelector" ), stringIDToTypeID( "selectionEnum" ) );
var idcopy = stringIDToTypeID( "copy" );
desc2.putBoolean( idcopy, true );
executeAction( stringIDToTypeID( "make" ), desc2, DialogModes.NO );
};
JJMack
Community Expert
JJMackCommunity ExpertRespuesta
Community Expert
June 10, 2020

Try duplicating the layer then name the new active layer.

newLayer =  somelayerobject.duplicate();

newLayer.name = "LayerName";

 

JJMack
Inspiring
June 10, 2020

I now have

 

	var newdLayer = docRef.activeLayer.duplicate();
	newdLayer.name = "BLUR";
	docRef.activeLayer = docRef.layers["BLUR"]
	docRef.activeLayer.applyGaussianBlur(20);

 

and it works, many thanks

 

Mike 

c.pfaffenbichler
Community Expert
Community Expert
June 10, 2020

I suspect 

var newdLayer = docRef.activeLayer.duplicate();
newdLayer.name = "BLUR";
newdLayer.applyGaussianBlur(20);

should suffice.