Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions real value to change comp duration

  • real value to change comp duration

    Posted by Rainier Raydán on August 30, 2017 at 7:56 pm

    Hi guys! I’m working in a script to change the duration (and other things) of the or selected comps. The problem is that the value that I get when I use alert(selectedComps.duration) is very strange for me. In the timeline we can see fps and timecode (0:00:00:00) but the value I get from that alert is “x.yyy”, I can see that x is the amount in seconds of the composition but after “.” they are decimals that I cant figure it out how it works. I soupose is the fps divided by a number I dont know…

    I’m thinking in a text box to get the first number (seconds), do praseFloat() and get a real number. Also other box to get the frames and apply a math function to it. Do you guys knows any math function I can use?

    Thanks!

    Andrei Popa replied 8 years, 8 months ago 2 Members · 7 Replies
  • 7 Replies
  • Andrei Popa

    August 31, 2017 at 8:10 am

    var compLength = selectedComps.duration;
    var minutes = Math.floor(compLength / 60);
    var seconds = Math.floor(compLength % 60);
    var frames = Math.round((compLength - Math.floor(compLength))/selectedComps.frameDuration);
    alert (minutes +":"+ seconds +":"+ frames);

    I don’t know if it works with multiple selected comps.

    Andrei

  • Rainier Raydán

    August 31, 2017 at 1:36 pm

    Nice! Thanks Andrei!

    But I need to change the duration of the comp with this values

    I want to set the minutes, the seconds and the number of frames with this UI but I dont know how!

  • Andrei Popa

    August 31, 2017 at 6:20 pm

    You just reverse the process. Lets say the variables for the texts of this GUI are sec,min,fps,frames.

    min*60 + sec + frames/fps

    Andrei

  • Rainier Raydán

    September 1, 2017 at 8:29 pm

    Ok I have this

    var compLength = app.project.activeItem.duration;
    var minutes =2
    var seconds = 15
    var frames = 20;

    minSec = (minutes*60)+seconds;

    realFrames = frames /app.project.activeItem.frameDuration;

    finalDuration = parseFloat (minSec +"."+realFrames);

    app.project.activeItem.duration = finalDuration;

    But the comp duration still wrong. It has to be 02:15:20 (it’s a 25 frames comp) but the script result is 02:15:13…

  • Andrei Popa

    September 2, 2017 at 6:09 am

    That is because you used frameDuration instead of fps. Fps is 1/frameDuration, which makes your realFrames value frames*app.project.activeItem.frameDuration. The script would be like this
    var compLength = app.project.activeItem.duration;
    var minutes =2
    var seconds = 15
    var frames = 20;

    minSec = (minutes*60)+seconds;

    realFrames = frames *app.project.activeItem.frameDuration;

    finalDuration = minSec +realFrames;

    app.project.activeItem.duration = finalDuration;

    Andrei

  • Rainier Raydán

    September 3, 2017 at 12:44 pm

    Wow! That help! It worked just fine but when the comp is 23.976 fps it doesnt work… when the minutes value its greater thant 0 the results in frame and in seconds doesnt match… minutes = 1, secondes = 10 and frames = 5 and the result is 0:01:10:03…

  • Andrei Popa

    September 4, 2017 at 6:51 am

    It seems that there is a problem with this framerate. Even if you put an integer as the duration, you get some frames.

    Andrei

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy