• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

Making a script that dynamically checks if property value have changed

Community Beginner ,
Oct 20, 2023 Oct 20, 2023

Copy link to clipboard

Copied

I was trying to automate the location of the layers in a Pre-comp, so each layer in the composition will be moved to begin when a property of the layer (like rotation) reaches a certain value.  

 

From some research, I learned that there isn't a feature to let me listen for events every time a property changes. I wonder if anyone has done something like this and has a solution that I can use as a starting point.

I'm new to the AE scripting, and so far my script can only move the layer at the wrong time, only when the code is executed.

 

var comp = app.project.activeItem;
var preComp = comp.layer("Pre-comp name");
var currentTime = comp.time;

if (preComp != null && preComp.source != null) {
    var layers = preComp.source.layers;
    var arrayLength = layers.length;
    for (var i = 1; i <= arrayLength; i++) {
        var workingLayer = layers[i];
        if (workingLayer.transform.rotationY <= 90) {
            workingLayer.startTime = currentTime;
        }
    }
}

 

 

The layer's rotation is adjusted by a parent object that is controlled by a Null. So when the parent reaches the angle needed, the child that inherits the rotation should be moved to the current time starting point.

TOPICS
Expressions , How to , Scripting

Views

284

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 20, 2023 Oct 20, 2023

Copy link to clipboard

Copied

As you already mentioned, there is no way to trigger such a script automatically (i.e. to run it automatically, when the rotation of the working layer changes).

 

Not sure exactly what problem you try to solve, which would require such an automatic trigger. But maybe you can write an expression on the opacity or position of the layers, to make the opacity 0 (or place them off-screen) before the rotation reaches the desired value? The benefit of expressions is that they react instantly to the change of any property values. But you can only apply expressions to property values and not change something like the start time of a layer with them. That's why I suggest to coontrol the visibility by opacity instead of start time.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 22, 2023 Oct 22, 2023

Copy link to clipboard

Copied

Thank you for your suggestion Mathias. Sadly I use videos that need to start at the given point of rotation, thus opacity won't allow me to start the videos on the right moment. I would rather seek a way to automate the proccess condering I may use 100 video clips. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 03, 2023 Nov 03, 2023

Copy link to clipboard

Copied

LATEST

You can set keys on the rotation, for example, key(1) is 0, key(2) is 90. And have that key(2) drive the timeRemap of the composition.
You can include something like this in the timeRemap of the composition and include your video in the composition.

var driver = thisLayer.transform.rotation;

if(driver.key(2)){
	linear(time, driver.key(2).time, driver.key(2).time+thisLayer.source.duration, key(1), key(2))
}else{
	0;
}

 
I've also uploaded my example on dropbox, which you can download it here.
https://www.dropbox.com/scl/fi/eatg2dqbvz6g8mz8qycgc/RotationDrivenTimeRemap.zip?rlkey=b1dluxaylvmi0...
Let me know if you need more help on this!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines