ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Scripting: shift markers from selected layers random within values

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Peter Zeet
Scripting: shift markers from selected layers random within values
on Apr 10, 2019 at 12:13:34 am

Hi there!
Have been trying to shift markers from a bunch of selected layers, and all ok, but when I try to add some randomness to the shifting, the markers of all the layers move the same amount of frames. I'd need the markers to move random within a min max, but having each layer a different shifting, so if these are 2 layers with 2 markers
*------------*---
*------------*---

after running the script, I'd love to get something like:
---*-----------*---
-----*-----------*----

and now I get:
---*---------*--
---*---------*--

the script is this so far:

//as seen on https://www.aenhancers.com/viewtopic.php?t=71 and tweaked a bit


app.beginUndoGroup("shiftMarkers");

var comp = app.project.activeItem;
var myLayers = app.project.activeItem.selectedLayers;
var newMarkers = new Array();
var newTimes = new Array();
var min=-3;
var max=3;
var ran=Math.floor(Math.random() * (max - min + 1)) + min;
var myLayer;


for (var j= 0; j< myLayers.length; j++){
myLayer = myLayers[j];
theMarker =myLayer.property("Marker")


for(var i = theMarker.numKeys; i >= 1; i--){

var markerVal = theMarker.keyValue(i);
newMarkers[newMarkers.length] = markerVal;
var markerKeyTime = theMarker.keyTime(i);
var newMarkerTime =markerKeyTime+(ran*comp.frameDuration);
newTimes[newTimes.length] = newMarkerTime;

// remove original markers
theMarker.removeKey(i);
}


// add new markers with new value.
for(var k = 0; k < newMarkers.length; k++) {
theMarker.setValueAtTime(newTimes[k], newMarkers[k]);

}

}


app.endUndoGroup();



Any ideas? Thanks!


Return to posts index

Dan Ebberts
Re: Scripting: shift markers from selected layers random within values
on Apr 10, 2019 at 12:32:34 am

I think you just need to move your ran calculation:

var ran=Math.floor(Math.random() * (max - min + 1)) + min;

inside your layer loop (j).


Dan



Return to posts index

Peter Zeet
Re: Scripting: shift markers from selected layers random within values
on Apr 10, 2019 at 12:43:39 am

oh! thanks!
That works, but now I have a side effect... from here



after running the script, now it seems it is not removing the old markers anymore




mmm maybe I should add another removal?


Return to posts index


Peter Zeet
Re: Scripting: shift markers from selected layers random within values
on Apr 29, 2019 at 7:46:04 pm

hi!
after some attempts, I think I couldn't figure it out properly... any ideas on this? I'm a bit lost
super thanks!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]