Auto Numbering in photoshop

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

Coinneach

Auto Numbering in photoshop

Post by Coinneach »

Hi,
I was wondering if there is any way for Photoshop to automatically change the value of a text field before printing.

At the moment i am printing gift vouchers 4 to a page and have to manually change the 3 digit serial number in each voucher before printing.
I realise that In Design could probably do this in seconds but I don't have access to that software (or the skills to use it )

Is there some way of scripting things so that the text fields would automatically change before being sent to print.

I am not using a large volume of these so it is not too onerous a task to do it by hand, but it is rather repetitive and boring.

Thanks for reading and I'd be grateful if anyone can suggest any possible solutions


Kenny

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

pfaffenbichler

Auto Numbering in photoshop

Post by pfaffenbichler »

Assuming you are talking about type layers without anything fancy (like combining different fonts, sizes, …) it seems feasible.
But why 3 numbers? Don’t you need to change all 4?
Coinneach

Auto Numbering in photoshop

Post by Coinneach »

Sorry. I meant three digits.
In all four cases.
The font and size is standardised In the text fields.
Thanks
pfaffenbichler

Auto Numbering in photoshop

Post by pfaffenbichler »

Are those four the only type layers in the document?
If not how are they identifiable?
Coinneach

Auto Numbering in photoshop

Post by Coinneach »

yes,
these are the only text fields.

at the moment they are identified by their contents but I can call them anything you care to suggest.


Thanks

Kenny
pfaffenbichler

Auto Numbering in photoshop

Post by pfaffenbichler »

This code will not be very fast, but it might suffice, so please give it a try:
Code: Select all// this script increases the numbers in type layers;
// it needs all type layers  to contain only numbers, though;
// 2013, use it at your own risk;
#target photoshop;
if (app.documents.length > 0) {
// get doc;
var myDocument = app.activeDocument;
// the type layer;
var typeLayers = collectTypeLayers(myDocument, []);
// add to numbers;
for (var m = 0; m < typeLayers.length; m++) {
   var theNumber = typeLayers[m].textItem.contents;
   typeLayers[m].textItem.contents = Number(theNumber) + typeLayers.length;
   }
};
//that’s it; thanks to xbytor;
////// buffer number with zeros //////
function bufferNumberWithZeros (number, places) {
   var theNumberString = String(number);
   for (var o = 0; o < (places - String(number).length); o++) {
      theNumberString = String("0" + theNumberString)
      };
   return theNumberString
   };
////// function collect type layers //////
function collectTypeLayers (theParent, allLayers) {
   if (!allLayers) {var allLayers = new Array}
   else {};
   for (var m = theParent.layers.length - 1; m >= 0;m--) {
      var theLayer = theParent.layers[m];
// apply the function to layersets;
      if (theLayer.typename == "ArtLayer") {
         if (theLayer.kind == LayerKind.TEXT) {allLayers.push(theLayer)}
         }
      else {
         allLayers = (collectTypeLayers(theLayer, allLayers))
// this line includes the layer groups;
         allLayers.push(theLayer);
         }
      };
   return allLayers
   };