Hello,
Second time I run into the same problem when creating a script for After Effects. There is no way to tell which layer is currently selected by the user in the timeline window.
The thing is that I can select one composition in project panel (or nothing at all), yet select a layer in already open tab for any other composition. It looks like AE Object model doesn't reflect this at all.
So basically, if I understood it correctly, there is NO way of telling which layer user have selected in his currently open tab. Is that correct ?
Thanks, M.
AE selected items trouble
Moderator: Paul Tuersley
-
- Posts: 62
- Joined: September 5th, 2006, 3:45 am
- Location: Chiswick, London, UK
- Contact:
Good news, this is directly referable from the API, though I think its worth building into a function just to perform a bit of checking on the active item. Like so:
It returns an array of currently selected layer objects.
Code: Select all
function getSelectedLayers()
{
var currentComp = app.project.activeItem;
if(currentComp instanceof CompItem) return(currentComp.selectedLayers); //Return the current selected layers
return false; //User didn't have a Comp open
}
- redefinery
- Posts: 112
- Joined: April 1st, 2005, 8:16 pm
- Location: CA
- Contact:
hi SFR75,SFR75 wrote:So basically, if I understood it correctly, there is NO way of telling which layer user have selected in his currently open tab. Is that correct ?
if the Project panel is not currently active, the app.project.activeItem attribute should give you the currently (or last) active composition, regardless of the selection in the Project panel. If the Project panel has focus, .activeItem is based on what's selected in that panel, regardless of what's open/active in any Composition viewer.
once you have an activeItem that's a comp, you can get the selected layers by accessing .selectedLayers, or .selectedLayers[0] for the first selected layer in that comp. be sure to check that .activeItem isn't null (for no selection or multiple selection) and is a CompItem, as in something like this:
Code: Select all
var activeComp = app.project.activeItem;
var firstSelectedLayer = null;
if ((activeComp != null) && (activeComp instanceof CompItem))
{
if (activeComp.selectedLayers.length > 0)
firstSelectedLayer = activeComp.selectedLayers[0];
}
Code: Select all
if (activeComp.selectedLayers.length == 1)

:jeff
-
- Posts: 62
- Joined: September 5th, 2006, 3:45 am
- Location: Chiswick, London, UK
- Contact:
Yes, and what jeff said 
