ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Scripting: shift markers from selected layers random within values

COW Forums : Adobe After Effects Expressions

FAQ   •   VIEW ALL   •   ADD A NEW POST   •   PRINT
Respond to this post   •   Return to posts index   •   Read entire thread


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!


Posts IndexRead Thread 


Current Message Thread:





© 2019 CreativeCOW.net All Rights Reserved
[TOP]