Copy link to clipboard
Copied
Hello,
I cannot get the following command to work in my script:
app.executeCommand(app.findMenuCommandId("New Comp from Selection..."));
however, the following does give me result of 2796:
alert(app.findMenuCommandId("New Comp from Selection..."));
So it does exist. Anyone gotten this to work? I need it for a script I am doing where I cannot use the traditional method of AddComp( ).
Thanks!
N
Copy link to clipboard
Copied
My first guess would be the dependency of that menu item having the project window active and FootageItems being selected for it to work. Running it via script, while not impossible, would require a bit more manual coding to make sure items are selected and so forth. Using that command would also be a bit unstable as you have already seen. Creating comps based on footage with scripting is fairly straight forward. I threw this together really fast by modifying a post I did previously here: http://forums.adobe.com/thread/1388596?tstart=30
This checks for selected items, verifies they are FootageItems and that they are at least one or more frames in duration. Helps avoid confusion with Solids and stills. The comp specs are built based on the footage specs. Width, height, duration, fps, and the name. The first half of this code is more for demonstration, the function can be pulled separately to be used easily enough in a script. Just feed the function argument an array of FootageItems objects.
var proj = app.project;
var itemSelection = proj.selection;
var totalItems = itemSelection.length;
var myFiles = new Array();
var curItem;
for(var i=0; i<totalItems; i++){
curItem = itemSelection;
if(curItem instanceof FootageItem && curItem.duration > 0){
myFiles = curItem;
}
}
if(myFiles.length > 0){
createCompsFromFootage(myFiles);
}
function createCompsFromFootage(myFiles){
try{
var myFilesLength, curFile, extFind, fileNameOnly, newComp;
myFilesLength = myFiles.length;
for(var c=0; c<myFilesLength; c++){
curFile = myFiles
extFind = curFile.name.toString().lastIndexOf(".");
fileNameOnly = curFile.name.substring(extFind, 0); //Removes file extension
newComp = app.project.items.addComp(fileNameOnly, curFile.width, curFile.height, 1, curFile.duration, curFile.frameRate);
newComp.layers.add(curFile); //Adds file to comp
}
}catch(err){alert("Error at line# " + err.line.toString() + "\r" + err.toString());}
Copy link to clipboard
Copied
The "&&" in the for loop should be the AND comparison operator. Just remove both "amp;" bits. This forum reformats entries made from an iPad for some reason.
Copy link to clipboard
Copied
Thanks for the reply. I was able to get it working due in part to your comment that the project window must be active. This seems to work for me (to make it active):
app.project.showWindow(false);
app.project.showWindow(true);
Kind of clunky, but I can now script the step of creating multiple comps through the dialog, which allows for comps 1 pixel in width (addComp() does not).
Thanks,
Nick
Copy link to clipboard
Copied
which allows for comps 1 pixel in width (addComp() does not)
Did not know that. Just tried it and sure enough you can make a 1x1 comp via the menu option in CS6 and CC. Interesting quirk.
Copy link to clipboard
Copied
Hasta la vista, baby....... Solution:
1. add footage
2. Creates a comp from the file and sets the comp active
{
var myfile = app.project.importFileWithDialog();
app.project.showWindow(false);
app.project.showWindow(true);
// File > New Comp from Selection
app.executeCommand(2796);
}
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more