🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.photoshop.scripting
Article #2

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

#2
From: christoph_pfaffenbichler
Date: Wed, 25 Mar 2009 06:25
84 lines
2644 bytes
Please keep in mind that I�m 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 didn�t 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.
Technical Details
Message-ID: <59b862ff.2@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!newshub.sdsu.edu!webcrossing
References: <59b862ff.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f5839,d232fecea0213b00
X-Google-Attributes: gidf5839,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII
From: christoph_pfaffenbichler@adobeforums.com
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.photoshop.scripting
Subject: Re: Script to edit actual text in type layer
 with number generation?
Message-ID: <59b862ff.2@webcrossing.la2eafNXanI>
Date: Tue, 24 Mar 2009 23:25:58 -0700
References: <59b862ff.-1@webcrossing.la2eafNXanI>
Lines: 53
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit