Activity › Forums › Adobe After Effects Expressions › Selecting a layer using Extendscript
-
Selecting a layer using Extendscript
Posted by Sky Shields on October 3, 2013 at 8:23 pmThis seems like a very simple scripting problem, but it has me stumped.
I’m trying to extract an audio layer’s amplitude as part of a script. I know that I can use
app.executeCommand(app.findMenuCommandId("Convert Audio to Keyframes"));to access the “Convert Audio to Keyframes” menu item, but first I need to select the right layer. I tried setting the activeItem by using
app.project.activeItem.activeItem = audioFile;but that doesn’t seem to work. Any ideas?
app.project.activeItem.activeItem = audioFile;
app.executeCommand(app.findMenuCommandId("Convert Audio to Keyframes"));Ted Mihu replied 11 years, 11 months ago 5 Members · 7 Replies -
7 Replies
-
Dan Ebberts
October 3, 2013 at 9:13 pmI think you just need to select the layer first (not tested, but should be close):
app.project.activeItem.layer(“your layer name”).selected = true;
Dan
-
Sky Shields
October 4, 2013 at 11:42 pmYes! Thank you, Dan. That was exactly what I needed to do.
audioComp.openInViewer();
audioFile.selected=true;
app.executeCommand(app.findMenuCommandId("Convert Audio to Keyframes"));–Sky
-
Billy Sides
April 30, 2014 at 3:39 pmOn a side note, how do you make sure there is nothing selected?
I’m trying this, but it’s not deselecting anything.app.project.activeItem.selectedLayers.selected = false;-bsides
-
Xavier Gomez
April 30, 2014 at 4:09 pm// (comp should be a CompItem)
var selLayers = comp.selectedLayers, n=selLayers.length;
while (n–) selLayers[n].selected = false;// or, if you are sure that app.project.activeItem is a comp opened in a viewer
app.executeCommand(2004); // “Deselect All”Xavier
-
Billy Sides
April 30, 2014 at 4:29 pmThank you for the quick response Xavier, that worked perfectly.
What document were you able to pull that from if any? I have the scripting guide and it doesn’t include that.Thanks again for the help.
-bsides
-
Xavier Gomez
April 30, 2014 at 7:16 pmFor the second way, to find a menu command ID, do
app.findMenuCommandById(commandName) // returns an integer, (0 if not found)
for “Deselect All” is gives 2004.
Then you inject that number in app.executeCommand(commandId);
You’ve got to be very sure of what panel is active and what item/layers/properties/etc are selected before using these… For “deselect all” a mistake is quite harmless, for “cut” it is another story.
Xavier
-
Ted Mihu
June 28, 2014 at 9:04 pmHi. I’m trying to automate a process at work and you seem to have exactly what I need but I can’t get it to work.
var selectedItems = app.project.selection;
var bodyComp = app.project.items[1];
var mouthComp = app.project.items[2];for (var i = 0; i < selectedItems.length; i++) {
var compName = selectedItems[i].name.substr(0,(selectedItems[i].name.length - 4));
var myComp = app.project.items.addComp(compName,1080,1920,1,1920,24);
myComp.layers.add(selectedItems[i]);
myComp.layers.add(bodyComp);
myComp.layers.add(mouthComp);
myComp.layer(1).timeRemapEnabled = true;//myComp.layer(1).timeRemap.expression = "A =
}for (var i = 0;
I'm trying to create compositions based on selected voice over tracks, rename the composition by the name of the VO minus the extension name, then import two pre-made compositions "Body Comp" and "Mouth Comp", as well the VO track themselves. The next part is what I'm having problems with.
I'm trying to get an audio amplitude null out of the audio track in each composition and then apply an expression to the time remap property (which I've successfully enabled) on the mouth loop composition. Trying to run the code out of the loop worked fine for one composition, but trying to do so for all the compositions gave me an error, saying that a ")" is expected after
app.project.item(i).layer(3).selected = true;Any suggestions?
<code />var selectedItems = app.project.selection;
var bodyComp = app.project.items[1];
var mouthComp = app.project.items[2];for (var i = 0; i < selectedItems.length; i++) {
var compName = selectedItems[i].name.substr(0,(selectedItems[i].name.length - 4));
var myComp = app.project.items.addComp(compName,1080,1920,1,1920,24);
myComp.layers.add(selectedItems[i]);
myComp.layers.add(bodyComp);
myComp.layers.add(mouthComp);
myComp.layer(1).timeRemapEnabled = true;//myComp.layer(1).timeRemap.expression = "A =
}for (var i = 0; <selectedItems.length; i++) {
if (app.project.item(i) instanceof compItem)
app.project.item(i).openInViewer();
app.project.item(i).layer(3).selected = true;
app.executeCommand(app.findMenuCommandId("Convert Audio to Keyframes"));
}
Reply to this Discussion! Login or Sign Up