Skip to main content
Participant
March 23, 2009
Question

Script to edit actual text in type layer with number generation?

  • March 23, 2009
  • 16 replies
  • 2334 views
Excuse me if this is a dumb question, is there a way to write a script that will edit the actual text in a Type layer?

For example, I have to create a few hundred slates. Each one has a year and an issue number. There are only 17 years I have to do, but hundreds of issues. I would like to create just a template for each year and run a script that creates a slate with a different issue number for each. They would run 001 to 100, for example.

Basically I would need to script something that opens a document, opens the type layer for editing and generates a number (counting 001 to ###), then repeats with a continuing number in each document.

Thanks for any advice you can give, or if you know of a script in existence that may be able to help me!
This topic has been closed for replies.

16 replies

c.pfaffenbichler
Community Expert
Community Expert
March 26, 2009
Its JavaScript, just copy it into a new File in ExtendScript Toolkit and save it into the Presets  Scripts-Folder in Photoshops program-folder.
Known Participant
March 26, 2009
Tried using this as it's pretty much what i need. Noticed the jpopts var is being ignored in the jpeg saves. I'm going to just batch them down to 90% quality, but would be nice to use this as is intented to work.

Best
Alastair
c.pfaffenbichler
Community Expert
Community Expert
March 25, 2009
Sorry, I forgot to mention: For previously posted Sript to work You would have the content of the TextLayer to be "001" or whatever the first number is supposed to be.
c.pfaffenbichler
Community Expert
Community Expert
March 25, 2009
Please keep in mind that Im a bit clumsy with Scripting, but You could try this:


// create scopies with progressive numbers in a type layer;

// use it at your own risk;

#target photoshop

var myDocument = app.activeDocument;

// the following line would work on the active layer;

// var theLayer = myDocument.activeLayer;

// this line takes the topmost layer;

var theLayer = myDocument.layers[0];

// get the name and location;

var docName = myDocument.name;

var basename = docName.match(/(.*)\.[^\.]+$/)[1];

var docPath = myDocument.path;

// jpg-options;

var jpgopts = new JPEGSaveOptions();

jpgopts.embedProfile = true;

jpgopts.formatOptions = FormatOptions.STANDARDBASELINE;

jpgopts.matte = MatteType.NONE;

jpgopts.quality = 10;

// create the new numbers and save jpgs;

if (theLayer.kind == LayerKind.TEXT) {

// save the first one;

myDocument.saveAs((new File(docPath+"/"+basename+"_"+theLayer.textItem.contents+".jpg")),jpgopts,true);

// create the rest, enter the desired total number - 1 instead of »99«;

for (var m = 0; m < 99; m++) {

var newNumber = bufferNumberWithZeros(Number(theLayer.textItem.contents) + 1, 3);

theLayer.textItem.contents = newNumber;

myDocument.saveAs((new File(docPath+"/"+basename+"_"+newNumber+".jpg")),jpgopts,true);

}

}

else {

alert ("the topmost is not a text-layer")

};

////// buffer the numbers-function //////

function bufferNumberWithZeros (number, places) {

var theNumberString = String(number);

for (var o = 0; o < (places - String(number).length); o++) {

theNumberString = String("0" + theNumberString)

};

return theNumberString

};
I didnt include dialog to enter the intended number, but You can easily enough edit the Script itself according to the necessities, and I did it just for saving jpgs, again something You could change Yourself.
Participant
March 24, 2009
Thanks for your response!

Each slate would be exactly the same except for the number, and I'm pretty much open to whatever would be easiest. I would imagine that the layer I want to edit would be on the top and be just "###" for text. It would always in the same position, then one or two layers below it would have other text, but would not be edited.

As far as output format, it doesn't really matter. .psd would be fine. I could always use the image processor if I needed to.

I'm on CS3 by the way.
c.pfaffenbichler
Community Expert
Community Expert
March 24, 2009
That sounds achievable, but when automating stuff a lot depends on regularity across the objects to be manipulated is there only ever one TypeLayer in the documents, is it always in the same position (topmost for example) in the stack?
What format would You want to save the resulting hundreds of files in? Do You want to keep the layered files or just save flattened jpgs?