Activity › Forums › Adobe After Effects Expressions › Could this be a simple script?
-
Could this be a simple script?
Posted by Tom Szymanski on August 9, 2020 at 4:26 pmHi,
I’ve never tried scripting before and would like to give it a shot, but for now, just need some help with what’s probably a simple script.
I have a project with a ton of compositions with text in each of them. I have a plugin called Auto Crop which works great.
What I’d like to be able to auto made is:
For selected compositions, open, autocrop (I have mapped to option+q), then Save Frame as File.Is that difficult to do? I’ve used actions in photoshop and that seemed really easy, basically hit record, do your things, then stop, and be able to play it back with a key command. Everything I’ve seen with scripting for AE is way more complicated.
Thanks!
TomTom Szymanski replied 5 years, 9 months ago 3 Members · 10 Replies -
10 Replies
-
David Gidali
August 9, 2020 at 10:09 pmHi there,
I’m not a pro scripter, and I’m sure someone with more knowledge will be able to provide a more thorough solution.
In principle I think that process is possible and quite simple to code. You won’t need to dive too deep into extendscript for that either.
I’m currently writing my first extendscript tool myself (I’ve written scripts for other software like 3DS max a long time ago, so I have some basic understanding of the process), and most of what I needed was super easy to find examples for online (a lot of it in this forum’s extensive archives).
If you’re not super busy I highly encourage trying to script it yourself, you’ll likely be inspired by the samples you find to write even more elaborate tools for yourself that will end up speeding your workflow significantly and make you feel superhuman!
Good luck. -
Tomas Bumbulevičius
August 10, 2020 at 10:04 amHey Tom, first of – could you let me know which AutoCrop version do you have? Just in case to be on the same page. The reason why this is needed – in order to actually ‘run’ other script in your script, assuming its done though GUI, you need to hit that “Crop” button in the panel. To do this, button must be found in the object model. But thats for the later.
Now few other things:
1. How selection of comps will be made?
2. How many comps there might be?
3. What export output is needed, does .png works for you?Find out more:
Motion Graphics Design & After Effects Tutorials
On YT
On VH -
Tom Szymanski
August 10, 2020 at 3:19 pmHi David,
What software are you using to write scripts in? It looked like there was something in creative cloud, but I’ve been having a hard time finding it. I think I’m missing something super remedial to get started – like where you write them, how to save them, where to put them, and how to activate or use them in AE. From there, what I’ve seen in some tutorials has made sense.
Thanks!
-
Tom Szymanski
August 10, 2020 at 3:29 pmHi Tom,
Thanks for the help!
I have autocrop 3 (https://aescripts.com/auto-crop/) and I mapped it to a option+q.1. Could be by folder, could be by clicking and highlighting, open to suggestions on this – I have an expression which makes the comp name the same as the text so I kind of need to be able to have the comp names be what they are.
2. About 300+ comps
3. .png is what I’d prefer – just a single frame,Watching some of your tutorials now. Thanks – looks like good stuff!
-
Tomas Bumbulevičius
August 12, 2020 at 9:49 amHey Tom,
thanks for clarifying! Few more things:
1. For simplicity, can we pre-assume all required comps will be in a single folder, which you would select in a project panel?
2. Where exported images should be stored, what location?
3. Can you provide a sample structure of comp names if it is consistent of some sort?
4. Are you using ‘Auto Crop’ option (the first button in the panel) or Crop Duration?Button triggering works, thus I will help you out on this one once above is covered (if it is still in questions, of course, let me know). Cheers!
Find out more:
Motion Graphics Design & After Effects Tutorials
On YT
On VH -
Tom Szymanski
August 13, 2020 at 8:57 pmThank you so much for the help! Been looking through your youtube videos. Great design and I like the data-driven aspect. I’d like to get into some more of that at some point, but for what I do there’s not as much call for it. But very slick.
Your scripting video was a good starting point to understanding it, and I can’t wait to learn more. I’ve been just beginning to dabble with that.
1. Yes, all comps can be in a single folder in the project panel.
2. Exported images can go to wherever, the desktop or a renders folder somewhere. Moving them afterwards shouldn’t be a problem.
3. Comp names for this, since they’re driving what the text is inside a project, tend to be just simple text like “classroom”, “teacher”, “teachers”, sometimes down to just numbers “1” etc.
(from the scripting video you made – maybe doing an array like from comp _ to _ with which lines they are in the project panel would work. I could put the other comps that don’t need to be rendered at the bottom after all of the rendered ones, or just in a different folder).
4. I’m using the plain “Auto Crop” option.I’m psyched for the help, and I look forward to getting to learn more!
Thanks! Tom -
Tomas Bumbulevičius
August 14, 2020 at 11:53 amHey Tom, you are too kind for me, but thanks, appreciate it!
Below is a script, which ALMOST does what is needed, with a few sidemarks.
How to run it:
1. Put all requires comps in a folder in project panel.
2. Select that folder.
3. Run the script.What DOESN’T work:
1. AutoCrop doesn’t seem to reflect the current activeItem, thus some different approach is needed, either to refresh the state or hit the button in a different way.
2. Due to the above frames are not properly exported as well.But with some tweaks here and there this should be made to work. I separated loops into two separate functions, due to the fact that some delay might be needed in the stack, to make it work as expected. However, that didn’t helped.
Tried adding sleeps and delays to make sure processes happens to successfully finish, but still no luck there either. Anyone has an idea what is missing here? Cheers!
/*
Script to export frames from comps, with AutoCrop 3.1.1
*///Constants
var PROJ = app.project,
AEP_FILE = PROJ.file,
ROOT_LOCATION = AEP_FILE.parent,
ROOT_LOCATION = createFolder(ROOT_LOCATION, "exported_frames"),
FRAMES_EXPORT_PATH = ROOT_LOCATION.toString(),
COMP_TIME = 0; //Timestamp in composition for frames exportingapp.beginUndoGroup("");
var curFolderSelection = PROJ.selection[0]; //Selected a SINGLE folder in project panel, containing ONLY compositions
processFolderCompsAutoCrop(curFolderSelection) //Autocrops comps in the folder
exportCroppedCompFrames(curFolderSelection) //Exports frames from comps in folderapp.endUndoGroup();
function processFolderCompsAutoCrop(curFolderSelection){
var curComp, autocropButton;
for (var i=1; i <= curFolderSelection.numItems; i++){
var curComp = curFolderSelection.item(i);
curComp.openInViewer();
autocropButton = standardCrop;
autocropButton.notify();
}
}function exportCroppedCompFrames(curFolderSelection){
var curComp, compName;
for (var i=1; i<= curFolderSelection.numItems; i++){
var curComp = curFolderSelection.item(i);
curComp.openInViewer();
compName = curComp.name;
curComp = curFolderSelection.item(i);
exportCompFrames(curComp, compName)
}
}function exportCompFrames(curComp, fileName){
var filePath = FRAMES_EXPORT_PATH + "/"
var saveFile = new File(filePath + "/" + fileName + ".png");
curComp.saveFrameToPng(COMP_TIME, saveFile);
}function createFolder(directory, folderName) {
var osFolder = new Folder(directory.toString() + "/" + folderName + "/");
var statusMessage;
if (!osFolder.exists) {
osFolder.create();
statusMessage = "Folder created."
} else {
statusMessage = "Folder exists."
}
return osFolder;
}Find out more:
Motion Graphics Design & After Effects Tutorials
On YT
On VH -
Tom Szymanski
August 14, 2020 at 4:07 pmAwesome, thanks for the help!
It gets me a lot closer and I appreciate it. I’ll try it out this weekend and I’m curious to dig into the scripting you used to understand it better.
Thank you!
-
Tomas Bumbulevičius
August 15, 2020 at 11:01 amHey Tom, in a worst case scenario what you could do – open all comps and autocrop them manually.
1. Open all comps.
2. Do your shortcut for Autocrop.
3. Click Ctrl/command + W to close active comp.
4. Repeat this quite fast with shortcuts available on hand.Then comment-out this line:
processFolderCompsAutoCrop(curFolderSelection) //Autocrops comps in the folderAnd at least you would get all comps exported to their new auto-cropped sized frames.
Basically the problem here is that AutoCrop in this way as I made it, is able to crop ONLY the last comp, even though all of them being made active. I am sure there are other ways calling that button, which I am not aware of. Thus maybe someone else can chime in (BTW, I made a test on Mac, in case it behaves differently on PC ! )
Cheers!
Find out more:
Motion Graphics Design & After Effects Tutorials
On YT
On VH -
Tom Szymanski
August 17, 2020 at 5:35 pmGotcha. I batched a bunch of them like you said, just being a little bit more of a machine myself with the shortcut keys. That cut down on the time a good bit.
I can see where highlighting a bunch fo them might confuse the autocrop part.
Would there be a way to do it as a cycle?
(not written in scripting because I’m not very good at it yet)
Open project / folder comp X+0
select none (I’ve realized having any layers selected confused autocrop)
Autocrop
Save as frameThen
Open project / folder comp X+1
(repeat)
Open project / folder comp X+2I don’t know how to stop it though.
For a different project like this I wanted to color each letter in a word in a certain order and built it so that there’s a slider for how many colors to pick from (since sometimes it was 4 colors, sometimes 6, sometimes up to 11) and when I adjusted the “how many colors” slider it told the text to start cycle over again after X number of colors. (all of which I got a lot of great help from some folks on Creative Cow)
But can a script ask the user for input? Like could the script say “How many comps do you want to process?” and you put in the number and then the X+1 through whatever number was typed in idea might work.
The new scripting stuff has me thinking about a lot of this in some fun ways. I appreciate the mental gymnastics.
Reply to this Discussion! Login or Sign Up