Activity › Forums › Adobe After Effects Expressions › Script work with timeline
-
Script work with timeline
Posted by Vasyl Iskovych on March 31, 2019 at 1:30 pmHello.
I want the script to add layers to the open composition.
I want to make the script work only if the “Timeline” panel is highlighted.
I add layers like this:
app.project.activeItem.layers.addNull();
But if the composition is selected in the “Project” panel, then the layer will be created in it.
It can be done so that in this case alert is displayed “select the timeline”; ?Tomas Bumbulevičius replied 7 years, 5 months ago 2 Members · 5 Replies -
5 Replies
-
Tomas Bumbulevičius
March 31, 2019 at 6:52 pmHello Vasyl,
is the composition selected in the project is the same as the activeItem?
You can ‘force’ AE to make composition active, by calling:
curComp.openInViewer();where ‘curComp’ should be comp item. Accordingly, you could grab selection from the project panel and use it for activating the viewer.
curComp = app.project.selection[0];where selection[0] would be selected item in the project panel, assuming its composition.
Whole scenario below, assuming that your selected comp in the project panel actually matches the one which you want to add item to. If it does not necessarily matches – then slight adjustments could be made.
var curComp = app.project.selection[0];
curComp.openInViewer();
curComp.layers.addNull();Find out more:
After Effects Tutorials: motion design, expressions, scripting. -
Vasyl Iskovych
April 1, 2019 at 7:46 amThanks for the answer.
But this is not what I need.
I need the script to work only in the composition that is open in the “Viewer”.
And if the selected other composition, then show the “alert” -
Tomas Bumbulevičius
April 1, 2019 at 4:03 pmOk, there can be two scenarios per your current explanation:
1. Script works in an active and opened composition.
2. Script does not work when other composition is selected in project panel.Now the main question is about the second point – selected WHERE?
But if the composition is selected in the “Project” panel, then the layer will be created in it.
It can be done so that in this case alert is displayed “select the timeline”; ?This message above from the original post overrides requirements and its not clear. Please clarify this further. Thanks!
Find out more:
After Effects Tutorials: motion design, expressions, scripting. -
Vasyl Iskovych
April 1, 2019 at 4:41 pmIt is necessary that the layer can be created only in the composition that is open on the “timeline”.
-
Tomas Bumbulevičius
April 1, 2019 at 4:46 pmComposition can be opened in the timeline, visible, but not active (meaning, it is not highlighted, and not accessible via ‘activeItem’).
With that said:
if (app.project.activeItem != null){
//Do any actions you want in an active comp
}else{
alert("Composition is not active in the project.")
}Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Reply to this Discussion! Login or Sign Up