1

Is there a way it can be scripted so that I can export every move in history to a separate png file while drawing with a brushenter image description here

For example, in the image attached, every brush stroke is recorded in the history panel, if I run a script, would a script be able to export all these moves to separate pngs, after I am finished with the drawing?

14
  • Yes I believe it's possible. Do you have any experience scripting for Photoshop?
    – Wolff
    Aug 31, 2021 at 20:07
  • I have no prior experience, but I was looking for some guidance here if anybody could help me make the script.. Aug 31, 2021 at 20:10
  • 1
    I think all you need is an action not a script. I have not done this.. but it seems to me all you need is file > export, edit > step backward, file > export, edit > step backward, file > export, edit > step backward, etc. An Action would break (stop) when it could no longer step backward.
    – Scott
    Aug 31, 2021 at 20:38
  • @Scott, true but what about file naming?
    – Wolff
    Aug 31, 2021 at 21:33
  • 2
    Do not vandalize your posts. By posting on this site, you've irrevocably granted the Stack Exchange network the right to distribute that content under the CC BY-SA 4.0 license for as long as it sees fit to do so. For alternatives to deletion, see: I've thought better of my question; can I delete it?
    – Ollie
    Oct 1, 2021 at 17:41

1 Answer 1

0

Following the initial idea of @Scott, you can do it using a script and an action. The Script is not mine. I just change it to save in png. The original save in tiff.

enter image description here

Open the script file and edit the output folder:

This line: "var folderPath = Folder("D:\Temp");"

Put the script file in the Scripts folder.

C:\Program Files\Adobe\Adobe Photoshop 2021\Presets\Scripts\Photoshop
AddNumberPng.jsx

Create an action with - history panel>menu>step forward, and File>scripts>AddNumberPng

enter image description here

You must draw in a transparent layer with no background layer if you want the transparency to be preserved. Assing a shortcut to that Action. In my test, I assigned the F2 key. Now go to the history state before the state you want it to save the first png and hit F2 then keep hitting it until you finish all the history states.

enter image description here

More: In additional to @Wolff's comment.

If the real wish is to save every separated Layer to png's, you can record the action just for the Script. Then you can use Alt+leftclick the layer eye icon to hide all the other layers and hit F2(to play the action). Repeat it to all layers.

About the code: My teacher said it is better you write it instead of copy/paste it. This way we can understand what is going on. But if someone really wants this code in text, I can provide it later.

enter image description here

As I`m not a bad person, here is the clean code:

    #target photoshop  
app.bringToFront();  //Leó 22/02/2018 tiff to png exporting extension changed.
main();  
function main(){  
if(!documents.length) return;  

var folderPath = Folder("D:\Temp");         //You can change this directory
if(!folderPath.exists) {  
    alert("Output folder does not exist!");  
    return;  
    }  

var fileName  = "filename";     //You can change the filename here
var fileType = "png";                                        
var fileList = new Array();  
var newNumber=0;  
var saveFile='';  
fileList = folderPath.getFiles((fileName + "*." + fileType));  
fileList.sort().reverse();  
if(fileList.length == 0){  
saveFile=File(folderPath + "/" + fileName + "0001." +fileType);  
 
activeDocument.saveAs(saveFile, SaveDocumentType.PNG, true, Extension.LOWERCASE);   
}else{  
    newNumber  = Number(fileList[0].toString().replace(/\....$/,'').match(/\d+$/)) +1;  
    saveFile=File(folderPath + "/" + fileName + zeroPad(newNumber, 4) + "." +fileType);  
activeDocument.saveAs(saveFile, SaveDocumentType.PNG, true, Extension.LOWERCASE);           }  
};  
function zeroPad(n, s) {   
   n = n.toString();   
   while (n.length < s)  n = '0' + n;   
   return n;   
};  
5
  • 1
    Err why is the script a screencapture?
    – joojaa
    Sep 8, 2021 at 15:04
  • @joojaa, reminds me of old computer magazines from the 80s which had page after page of code you had to enter manually. 😂
    – Wolff
    Sep 8, 2021 at 15:14
  • I'm sure the script works and answers the question as it stands. But if you read the comments below the answer, the OP seems to want "every stroke is in its own layer". Not the accumulated strokes. This might be an XY problem. The OP never edited the question though, so I guess this answers what was asked initially.
    – Wolff
    Sep 8, 2021 at 15:15
  • @LeoNas - this is some amazing work! Thank you so much. This is suitable for the work I am doing. And, this is kind of helpful in comparison to saving each stroke in it's own layer I suppose. Sep 9, 2021 at 18:59
  • @Wolff - Yes, this solves my query and works for what I wanted to achieve! I really appreciate your inputs on this Sep 9, 2021 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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