Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe Photoshop Scripting text causes mac and pc to run out of memory

  • Scripting text causes mac and pc to run out of memory

    Posted by Rob Stemm on February 27, 2008 at 3:39 am

    Hello all,

    I’ve written a script that reads text in an array and assigns that text to the selected textItem (Selected Text Layer in Photoshop). This works great for saving many files in a short amount of time, but there seems to be a memory problem if my selected text layer has different character styles. For example: if my text layer has Faux Bold or Small Caps turned on (In the Character window) when running the script. Photoshop will quickly eat up all of my computers memory making it non-responssive. This occurs on both PC and MAC. Is there any workaround to this? I’d like to be able to use these character styles on my fonts when running this simple script. Any help would be much appreciated.

    Below is the script I’m running.

    Thanks,
    Rob

    ///////////////////////////////////////////////////
    var defaultRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;

    //POINTING TO THE PATH WHERE THE FILES SHOULD BE SAVED
    var cPath = Folder.selectDialog(“Select a folder for the output files”);

    //ARRAY OF TEXT TO POPULATE TEXTITEM
    var textArray = [
    “Sample Text test 1”,
    “here is some more text you would like”,
    “\”This is an example of a quote\””,
    “Hope everything is going well”,
    “I’d like some dinner now”,
    “Time is of the essance”,
    “Do we need to go on?”,
    “\”Me\” This is me in quotes”,
    “Colorado is a great state”,
    “Do you like to rock climb?”
    ]

    //ARRAY OF FILE NAMES
    var fNameArray = [
    “01”,
    “02”,
    “03”,
    “04”,
    “05”,
    “06”,
    “07”,
    “08”,
    “09”,
    “10”
    ]

    var AD = app.activeDocument

    //LOOP THAT DOES ALL OF THE WORK
    for(a=1;a<=textArray.length;a++) { var TextLayer = AD.activeLayer; var txtRef = TextLayer.textItem; txtRef.contents = textArray[a-1]; var newName = ""; var newName = fNameArray[a-1]; saveForWebPNG(cPath,AD,100,newName); } alert("I'm Done :)"); //SAVE PNG FUNCTION function saveForWebPNG(toWhere,file,qual,name) { toWhere = new File(toWhere+"/"+name+".png"); var opts = new ExportOptionsSaveForWeb(); opts.interlaced = false; opts.PNG8 = false; opts.transparency = true; opts.format = SaveDocumentType.PNG; opts.includeProfile = false; file.exportDocument(toWhere, ExportType.SAVEFORWEB, opts); } app.preferences.rulerUnits = defaultRulerUnits;

    Rob Stemm replied 18 years, 2 months ago 2 Members · 4 Replies
  • 4 Replies
  • Ekim Wahs

    February 27, 2008 at 5:58 pm

    Once I set the contained quotes to single quote instead of double quotes in order for the script to run, I have not had a problem running your script with Faux Bold and Small Caps on the original type layer. Are you updated to 10.0.1? Do you get out of memory error if you save without going through save for web?

    Mike Shaw
    Photoshop QE

  • Rob Stemm

    February 27, 2008 at 8:47 pm

    Mike,

    I’m running Photoshop CS2 Version 9.0.2. I’ve tried saving without going through Save for Web and this doesn’t seem to help. I’ve also tried changing the quotes and removing many of the declared variables outside of the for loop. Below is some optimized code for the above as well as moving the loop into a main function. I’ve removed all instances of “‘s in the array. Is this just a problem with CS2? I’ve even tried using a different font and setting the faux bold / small caps on the actual text layer instead of through script.

    Any other ideas. Thanks for your suggestions.

    Rob

    ///////////////////////////////////////////////////////////

    var defaultRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;

    //POINTING TO THE PATH WHERE THE FILES SHOULD BE SAVED
    var cPath = Folder.selectDialog(“Select a folder for the output files”);

    //ARRAY OF TEXT TO POPULATE TEXTITEM
    var textArray = [
    “Sample Text test 1”,
    “here is some more text you would like”,
    “This is an example of a quote”,
    “Hope everything is going well”,
    “Id like some dinner now”,
    “Time is of the essance”,
    “Do we need to go on?”,
    “Me This is me in quotes”,
    “Colorado is a great state”,
    “Do you like to rock climb?”
    ]

    //ARRAY OF FILE NAMES
    var fNameArray = [
    “01”,
    “02”,
    “03”,
    “04”,
    “05”,
    “06”,
    “07”,
    “08”,
    “09”,
    “10”
    ]

    var AD = app.activeDocument;

    var TextLayer = AD.activeLayer;

    var txtRef = TextLayer.textItem;
    txtRef.fauxBold = true;
    txtRef.capitalization = TextCase.SMALLCAPS;

    var newName = “”;

    function myMainApp()
    {

    //LOOP THAT DOES ALL OF THE WORK
    for(var a=1;a<=textArray.length;a++) { try { txtRef.contents = textArray[a-1]; newName = fNameArray[a-1]; saveMyFile(cPath,AD,newName); } catch(e) { alert("Error Caught: " + e); } } alert("I'm Done :)"); } function saveMyFile(toWhere,file,name) { toWhere = new File(toWhere+"/"+name+".png"); saveOptions = new PNGSaveOptions(); file.saveAs(toWhere, saveOptions, true, Extension.LOWERCASE); } myMainApp(); app.preferences.rulerUnits = defaultRulerUnits; Rob Stemm

  • Ekim Wahs

    February 27, 2008 at 10:47 pm

    OK I see the slow down when using Faux Bold in CS2. If I just use small caps is seems to be going OK. Unfortunately I have not found a work around for you in CS2. CS3 looks to be handling this much better than CS2.

    Mike Shaw
    Photoshop QE

  • Rob Stemm

    February 28, 2008 at 4:13 am

    Thanks for your help. Looks like I finally have to go for the upgrade.

    Rob

    Rob Stemm

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy