Skip to main content
Participant
August 18, 2010
Question

Add layers from other psd file and retain text layers (Batch processing)

  • August 18, 2010
  • 1 reply
  • 2569 views

I want to batch process a large number of portraits adding text info from the filename (year_name_number.jpg) to existing text layers. I want to make a template psd file containg the correct labeled text layers formatted and adjusted (With bleding effects and more) How can i add layers from an other psd file to the active document and retaining the text layers editable. The place command in PS5 adds the file as a smart object, no use.

Any ideas?

I tried the combined action/script way, but no joy so far. Right now i am making the text layers with a action, then calling the script from the action. It works but its difficult to make different templates from adjusting a action.


The code i am using now (in combination with a action creating the 3 text layers and other grapchical elements)

var docRef = activeDocument;

// strip the extension off


var fileNameNoExtension = docRef.name;
fileNameNoExtension = fileNameNoExtension.split( "_" );
if ( fileNameNoExtension.length > 1 ) {
                fileNameNoExtension.length--;
}

fileNameNoExtension = fileNameNoExtension.join("_");

var myString = fileNameNoExtension;
var mySplitResult = myString.split("_");

var textLayer = docReflayers['Year']; // define the existing text layer to a var
docRef.activeLayer = textLayer;
textLayer.kind = LayerKind.TEXT;
var T1 = textLayer.textItem;
T1.contents = mySplitResult[0]

var textLayer = docRef.layers['Name']; // define the existing text layer to a var
docRef.activeLayer = textLayer;
textLayer.kind = LayerKind.TEXT;
var T2 = textLayer.textItem;
T2.contents = mySplitResult[1]

var textLayer = docRef.layers['Number']; // define the existing text layer to a var
docRef.activeLayer = textLayer;
textLayer.kind = LayerKind.TEXT;
var T3 = textLayer.textItem;
T3.contents = mySplitResult[2]

Thanks

Eivind

This topic has been closed for replies.

1 reply

JJMack
Community Expert
Community Expert
August 18, 2010

norway_photo wrote:

I want to batch process a large number of portraits adding text info from the filename (year_name_number.jpg) to existing text layers. I want to make a template psd file containg the correct labeled text layers formatted and adjusted (With bleding effects and more) How can i add layers from an other psd file to the active document and retaining the text layers editable.

Thanks

Eivind

Your description does not seem to make sense to me.  It reads more like you want to add a new text to your portrait images using an existing text layer that is in a template psd file. It seems you want to copy that text layer including  its blending layer style effects into the current portrait image document and also edit the text in the copy of the text layer to add additional text namely date and filename.   Are all the portrait images the same size so the position will match the template file?  What is the additional text in the template psd text layer.  You may have be better off creating a script that prompts for the additional text or retrieves the template psd text layerbv then process the images in your portrait folder adding the text layer and adding a layer style to it. Layer styles can change a layers blending as well as adding styles effects. You could save the your text layer style as a name of your choice an use the ScriptListener to generate the script code to apply it the the current layer would be the text layer you just added.  If your portrait image files vary in pixel size and resolution you will also need to also adjust the font size and text layers location.             

JJMack
Participant
August 18, 2010

Thanks for your reply

All my portraits are the same size and the template file containing the text layers are also the same size.

By having a template file with logos, text layers and other elements i can easily update the template the script uses.

Here is my intended workflow:

- A set of same size portraits labeled "year_name_number.jpg"

- A template.psd os same size with graphical elements and text layers (named "year", "name" and "number")

- A script or action copy/pasting og adding all layers from the template.psd file to the open portrait file, retaining text layers editable.

- A script (The one i have working) changing the text layers added from the template to text from the filename.

- A action saving this as a PDF ready for print.

This way i can process a large number of portraits, add names and other information and save it as a file ready for print.

I can image it is much easier to edit a template than writing a script or an action creating all the graphical elements.

And even better, to change this template for different customers/departments/logos.

Basically i need a way to add layers to an open file using a batch file or script.

Eivind

Paul Riggott
Inspiring
August 18, 2010

Here is the basics, it needs that your portrait is open in Photoshop



//Amend to suit
//The template file Must only have the text layers with thier own styles!
var Template = File("/c/Folder1/FolderWhatever/Template.psd");
open(Template);
selectAllLayers();
activeDocument.activeLayer.duplicate(app.documents[0] );
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, '');
var NameParts = Name.split('_');
activeDocument.activeLayer = activeDocument.artLayers.getByName('Year');
activeDocument.activeLayer.textItem.contents = NameParts[0];
activeDocument.activeLayer = activeDocument.artLayers.getByName('Name');
activeDocument.activeLayer.textItem.contents = NameParts[1];
activeDocument.activeLayer = activeDocument.artLayers.getByName('Number');
activeDocument.activeLayer.textItem.contents = NameParts[2];

function selectAllLayers() {
    var desc111 = new ActionDescriptor();
        var ref23 = new ActionReference();
        ref23.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
    desc111.putReference( charIDToTypeID('null'), ref23 );
    executeAction( stringIDToTypeID('selectAllLayers'), desc111, DialogModes.NO );
};