hi i need to find out the expression for creating a comp from a selected item in the project panel.
i know there is an option in after effects in file -> new comp from selection. but i need it as part of a script, and so that it automatically sets the dimensions of the comp to any item in the selection
can anyone please help meeeeeee.x
Sam
You have to roll your own but it's easy enough.
if (app.project.selection.length == 1) {
var sourceItem = app.project.selection[0];
app.project.items.addComp(sourceItem.name + " copy", sourceItem.width, sourceItem.height, sourceItem.pixelAspect, sourceItem.duration, sourceItem.frameRate);
} else {
alert("select one item in project window");
}
this is great, but half way there....this seems to create an empty comp and only if one of the footage items is selected. I meant create a comp from a folder selection (with footage inside) using the details of the footage within to set comp settings. And then once the comp is created - all of the items within the original folder will now be in the comp.
Yes, I was just giving you an example to get you started. I'd generally suggest checking out AE's CS3 scripting guide and the Javascript Tools Guide pdfs for documentation, and posting questions along with your code so far when you get stuck. You can study the various examples on here and places like aenhancers.com to get a better understanding of the syntax.
And one minor point, expressions (javascript that controls a property value) and scripting (javascript that controls After Effects) aren't exactly the same thing. In this case we're talking about scripting, not expressions.
Here's an example that should be closer to what you want:
var frameRate = 30;
var maxDuration = 10;
var maxWidth = 10;
var maxHeight = 10;
var pixelAspect = 1;
var x,y, curItem, thisItem, theComp;
for (x = 1; x <= app.project.rootFolder.numItems; x++) { // loop through items in root folder only
curItem = app.project.rootFolder.item(x);
if (curItem.selected && curItem instanceof FolderItem) { // if it's selected and a folder
for (y = 1; y <= curItem.numItems; y++) { // loop through the folder's items
thisItem = curItem.item(y);
if (thisItem instanceof FootageItem) { // if it's footage
if (thisItem.hasVideo) { // if it has video
maxWidth = Math.max(maxWidth, thisItem.width); // record this footage width if largest
maxHeight = Math.max(maxHeight, thisItem.height); // record this footage height if largest
pixelAspect = thisItem.pixelAspect; // record aspect ratio
if (!thisItem.mainSource.isStill) { // if it isn't a still record frame rate and duration if longest
maxDuration = Math.max(maxDuration, thisItem.duration);
frameRate = thisItem.frameRate;
}
} else { // must be audio. record duration if longest
maxDuration = Math.max(maxDuration, thisItem.duration);
}
}
}
theComp = app.project.items.addComp(curItem.name, maxWidth, maxHeight, pixelAspect, maxDuration, frameRate); // add comp with max values and folder name
for (y = 1; y <= curItem.numItems; y++) { // loop through items in folder again, adding them to comp if they are footage
thisItem = curItem.item(y);
if (thisItem instanceof FootageItem) {
theComp.layers.add(thisItem);
}
}
}
}
North America
Europe, Middle East and Africa
Asia Pacific