Copy link to clipboard
Copied
Hello!
I've never scripted anything but I also couldn't find this information online so I'm sorry if it doesn't make sense.
Here's what I'd like: a script that every x amout of time saves a png or jpeg of my artboards to a folder. The idea is to use the images to make a procreate-type timelapse of the workflow.
Could this work?
Copy link to clipboard
Copied
JavaScript has a built-in Date object. So I suppose in theory this could be done, but I have not tried anything like this, so I can't speak from experience. I will wait to see what other people suggest.
Copy link to clipboard
Copied
You couldn't do this with a regular Illustrator script. When the script is running, you don't have access to the UI. If the script is using some kind of pause or delay to wait for a certain time of day (or time interval) then you don't have access to the UI to continue working on your artwork.
You would need to use some kind of external workflow which contains the timer and periodically sends commands to Illustrator to export your artboard. I've never used it before, but i've heard a fair amount about keyboard maestro which allows you to set up all kinds of macros using all sorts of triggers. One of those triggers appears to be a periodic trigger which lets you set a time interval to periodically run a task. I'm sure this could be leveraged to export files while you worked.
Copy link to clipboard
Copied
oh, okay makes sense. Thank you I'll take a look into it.
Copy link to clipboard
Copied
Also there is this tutorial from a while ago, but actions seems unreliablem- for example, what's it do when there's no document and it's still running? So I suggest going with William's answer.
Copy link to clipboard
Copied
Hello everyone!
Hope you can help me one more time! I adapted a script I found, which is as follows. And then used a third party to loop for me. This seems to work just fine, except that the loop overwrites the previous file, so I need the script to create an unique extension. I thought a good idea would timestamp the file but I don't know how.
Any ideas?
function saveAsPNG() {
var pngFile = new File(app.activeDocument.path + "/" + app.activeDocument.name.split('.')[0] + '.png');
var resolution = 72;
var opts = new ImageCaptureOptions();
opts.resolution = resolution;
opts.antiAliasing = true;
opts.transparency = false;
try {
app.activeDocument.imageCapture(pngFile, app.activeDocument.clipbounds, opts);
} catch (e) {
}
}
saveAsPNG();
Copy link to clipboard
Copied
Do this:
var pngFile = new File(app.activeDocument.path + "/" + app.activeDocument.name.split('.')[0] + '-' + (new Date().getTime()) + '.png')
Also be aware when using split by dot, any file names which have a dot in them would produce an icorrect result.
I would do app.activeDocument.name.replace(/\..{2, 4}$/, "") which trims off all characters after the very last dot, provided there are only between 2-4 characters in the text after that dot. This takes care of most extensions that I know of being used regularly for the kinds of files which can be opened in Illustrator.
Copy link to clipboard
Copied
Thank you! This works. I think the time and date are messed up in format but it doesn't matter since I don't really need them, just the unique number which it gives me!
Copy link to clipboard
Copied
Out of interest, what third-party are you using?
Copy link to clipboard
Copied
The numbers there are milliseconds since "midnight of January 1, 1970". If you need to, you may use javascript to do some more extensive time formatting, but in any case you can get all the properties of the date such as the year/hour, etc. if you had to by passing in the timestamps into a new Date(timestamp) function.
So without any further work, you can still rest assured that inside of those numbers there's encoded information that could be used to get the hour, minute, AM/PM if that's ever needed.
Copy link to clipboard
Copied
I'm just replying to document the results and since @femkeblanco asked about what third party I used.
First I adapted an script to save my artboard as a png file in the same folder as the original document with a timestamp (this code) which ended up like this
function saveAsPNG() {
var pngFile = new File(app.activeDocument.path + "/" + app.activeDocument.name.split('.')[0] + '-' + (new Date().getTime()) + '.png')
var resolution = 72;
var opts = new ImageCaptureOptions();
opts.resolution = resolution;
opts.antiAliasing = true;
opts.transparency = false;
try {
app.activeDocument.imageCapture(pngFile, app.activeDocument.clipbounds, opts);
} catch (e) {
}
}
saveAsPNG();
Then I used AutoHotKey (I'm on windows) to make a simple timed loop that when illustrator windows are active, every x miliseconds (i believe) it just replays the code which runs the script!
#Persistent
; Save the file every second.
SetTimer, AutoSave, 1000, On
AutoSave:
IfWinActive, ahk_class illustrator
Run, Illustrator.exe D:\BIBLIOTECA\SCRIPTS\SaveAsPNG.jsx
return
Sometimes it lags a tiiiiny bit when runing the script but nothing that bothers me, so far.
Copy link to clipboard
Copied
Thanks.