0

I am trying to create a basic animation in which a white text object is a clipping mask for a blood drip graphic that slowly moves down to fill in the text. My plan is to create multiple frames and piece them together in FinalCut as the beginning of a video. I found a script that does what I am looking to do:

Script to move layer in photoshop

I am unable to get the script to work, and am given the following error:

"Error 2: docReg is undefined

Line: 20 -> docRef.exportDocument (pngFile, ExportType.SAVEFORWEB, opts);"

Here is the js that I am using:

// Save selected layer to variable:

app.preferences.rulerUnits = Units.PIXELS;

for (var dy = 1; dy < 50 ; dy++) {

activeDocument.activeLayer.translate(0,2);


        var opts;
        opts = new ExportOptionsSaveForWeb();
        opts.format = SaveDocumentType.PNG;
        opts.PNG8 = false;
        opts.quality = 100;
        var suffix = zeroPad(dy,5)
    var pngFile = new File("/Desktop/filename"+suffix+".png");

    //Folder path for new images

    docRef.exportDocument (pngFile, ExportType.SAVEFORWEB, opts);

}

    function zeroPad(n, s) {   
    n = n.toString();   
    while (n.length < s)  n = '0' + n;   
    return n;

}; 

Thank you for your help!

  • add var docRef = app.activeDocument; on the first line and try to execute again because in your script there isn't docRef defined and it seems you want to export from activeDocument :) – Mr.Online May 14 at 4:48
  • Edit : you don't even need to define it. read answer and use that script and it should work – Mr.Online May 14 at 4:54
  • That worked! Thank you so, so, so much. :) – ahuygen May 14 at 4:56
  • use my edited script ; it'll help you to add variability in the desired name :) – Mr.Online May 14 at 4:59
1

it's cause docRef isn't defined in script

here is modified script

// Save selected layer to variable:

var fileName = prompt("Enter File Name","");

app.preferences.rulerUnits = Units.PIXELS;

for (var dy = 1; dy < 50 ; dy++) {

activeDocument.activeLayer.translate(0,2);


        var opts;
        opts = new ExportOptionsSaveForWeb();
        opts.format = SaveDocumentType.PNG;
        opts.PNG8 = false;
        opts.quality = 100;
        var suffix = zeroPad(dy,5)
    var pngFile = new File("~/Desktop/"+fileName+suffix+".png");

    //Folder path for new images

    app.activeDocument.exportDocument (pngFile, ExportType.SAVEFORWEB, opts);

}

    function zeroPad(n, s) {   
    n = n.toString();   
    while (n.length < s)  n = '0' + n;   
    return n;

};

Edit : this one will now ask you for filename

  • Thanks again! You saved me a ton of time and frustration. – ahuygen May 14 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.