Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Mar 23, 2009 Mar 23, 2009
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!
TOPICS
Actions and scripting
2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Mar 24, 2009 Mar 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?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 24, 2009 Mar 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2009 Mar 24, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2009 Mar 24, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 26, 2009 Mar 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 26, 2009 Mar 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 26, 2009 Mar 26, 2009
Oh sorry just editted as you were answering previous question . I'm working with script now.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 26, 2009 Mar 26, 2009
So just to repeat myself, jpopts var being ignored in script. I event set it to 1 and same file size.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 26, 2009 Mar 26, 2009
In case You edited the Script, please go over it and make sure that the variable-name is always written exactly the same; other than that I wouldnt know how it could happen that the settings get ignored.
Or maybe, if the file is really small in pixel-dimensions, the size depends more on the embedded profile  
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 26, 2009 Mar 26, 2009
Well further examination shows image is showing jpeg deteriation but file size is still 60K as is full quality. Batching save for web at quality=9 got them down to 4K.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 26, 2009 Mar 26, 2009
Yes must be "save for web" removes the profile as opposed to regular save.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 26, 2009 Mar 26, 2009
Actually I just checked the script and I had changed line 29 to:

jpgopts.embedProfile = false;

so can't be the profile.

Anyhow I've got the result I wanted. Thanks for the script!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 26, 2009 Mar 26, 2009
The problem is the metadata not the profile. The profile is saved as a string ie 'Adobe RGB'. The metadata adds about 32k to a file.

Save for web removes the metadata and has an option for the profile
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 26, 2009 Mar 26, 2009
WEP, instead of batching after the fact You could try including the Save For Web in the Script  Â»Photoshop CS4 JavaScript Ref.pdf« should contain all the necessary information.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 26, 2009 Mar 26, 2009
Yes, good idea. I'm on CS3 but this command should be supported I guess.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 26, 2009 Mar 26, 2009
Wide_Eyed_Pupil@adobeforums.com wrote:
> Yes, good idea. I'm on CS3 but this command should be supported I guess.

Document.exportDocument takes ExportOptionsSaveForWeb as an argument.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 26, 2009 Mar 26, 2009
LATEST
I want to extend this script to concatenate the numbered images into a horizontal filmstrip type of image containing all of them (say 40 to 1 in left to right order). I started a new thread as it seemed sensible.

http://www.adobeforums.com/webx/.59b86c81
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines