Skip to main content
yon1313
Known Participant
October 15, 2016
Answered

change time of the marker key

  • October 15, 2016
  • 2 replies
  • 1480 views

Hi,

How can I change time of the marker key?

This topic has been closed for replies.
Correct answer Alex White

Unfortunately you can't.

But you can duplicate you marker and set new time for it.

In the example below we will get first marker on the layer, create a new marker with the same parametrs but second later and remove the first one.

var comp = app.project.activeItem;  // current composition

var layer = comp.selectedLayers[0]; // selected layer

var myMarkers = layer.marker;

var m = myMarkers.keyValue(1);  // get first marker on the layer

var p = m.getParameters();  // object with marker's parametrs

var mTime = myMarkers.keyTime(1);// get time of the first marker

var newMarker = new MarkerValue(m.comment, m.chapter, m.url, m.frameTarget, m.cuePointName, p); // create new marker object

myMarkers.setValueAtTime(mTime+1, newMarker);   // set the same marker but one second later

myMarkers.removeKey(1); // remove the original marker

2 replies

March 1, 2019

Hi! sorry to bring up this old thread, but I was trying to figure out how to adapt the code to make it work on all the selected layers at the same time, and not only 1 selected layer.

Any ideas?  thanks!

Alex White
Alex WhiteCorrect answer
Legend
October 16, 2016

Unfortunately you can't.

But you can duplicate you marker and set new time for it.

In the example below we will get first marker on the layer, create a new marker with the same parametrs but second later and remove the first one.

var comp = app.project.activeItem;  // current composition

var layer = comp.selectedLayers[0]; // selected layer

var myMarkers = layer.marker;

var m = myMarkers.keyValue(1);  // get first marker on the layer

var p = m.getParameters();  // object with marker's parametrs

var mTime = myMarkers.keyTime(1);// get time of the first marker

var newMarker = new MarkerValue(m.comment, m.chapter, m.url, m.frameTarget, m.cuePointName, p); // create new marker object

myMarkers.setValueAtTime(mTime+1, newMarker);   // set the same marker but one second later

myMarkers.removeKey(1); // remove the original marker

yon1313
yon1313Author
Known Participant
October 16, 2016

Tnks Alex+White ,

But how can I do this of the Some markers (not one marker)?

Alex White
Legend
October 16, 2016

Here is an example on how to manage all markers on the layer.

But you should be careful with setting new time. If you will try to shift you first marker in time later than the second marker, this code won't work correctly and to have a workaround here, you would probably need to create a multi-array with all markers, remove existing and set new shifted in time.

var comp = app.project.activeItem;  // current composition 

var myLayer = comp.selectedLayers[0]; // selected layer 

  replaceMarkers(myLayer, 1); // shift markers in one sec

function replaceMarkers(layer, shiftTime){ 

var myMarkers = layer.marker;

if (myMarkers.numKeys == 0) {   alert("There is no markers on layer "+ layer.name); return false; }

    /*  LOOP THROUGH ALL MARKERS  */

    for (var i = 1; i <= myMarkers.numKeys; i += 1) {

        var m = myMarkers.keyValue(i);  // get first marker on the layer 

         

        var p = m.getParameters();  // object with marker's parametrs 

        var mTime = myMarkers.keyTime(i);// get time of the first marker 

         

        var newMarker = new MarkerValue(m.comment, m.chapter, m.url, m.frameTarget, m.cuePointName, p); // create new marker object 

         

        myMarkers.setValueAtTime(mTime+shiftTime, newMarker);   // set the same marker but one second later 

        myMarkers.removeKey(i); // remove the original marker

    }

};