Converting Frames to Seconds

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
scottmiles
Posts: 2
Joined: January 14th, 2010, 6:45 pm
Location: Seattle, Washington - USA

I've been working on a simple piece of code to place equidistant markers on a selected layer. Originally, I wrote the script to space the markers in increments of seconds (5 seconds in this example) and it seemed to work fine:


var myComp = app.project.activeItem;
var myLayer = myComp.selectedLayers[0];
var marker = myLayer.property("marker");
var mkrVal = new MarkerValue("");
var startTime = myLayer.inPoint;
var endTime = myLayer.outPoint;
var curTime = app.project.activeItem.time;
var layerDur = myLayer.outPoint - myLayer.inPoint;
var tm = 0;



var usrIncSec = 5


// Make Markers (Seconds)

tm = tm + startTime;

while (tm <= endTime - usrIncSec){

marker.setValueAtTime(tm, mkrVal);

for (var tm = (tm + usrIncSec); tm<=marker.numKeys; tm++);
{
for (var nbrMkrs = 1; nbrMkrs<=marker.numKeys; nbrMkrs++);
}

marker.setValueAtTime(tm, mkrVal);

}//End While



//EOF

Image


Then I wrote a piece of code to do the same thing in increments of frames but the script produced unintended results:


var myComp = app.project.activeItem;
var myLayer = myComp.selectedLayers[0];
var marker = myLayer.property("marker");
var mkrVal = new MarkerValue("");
var startTime = myLayer.inPoint;
var endTime = myLayer.outPoint;
var curTime = app.project.activeItem.time;
var layerDur = myLayer.outPoint - myLayer.inPoint;
var tm = 0;
var nbrMkrs = 0;
var frmDur = myComp.frameDuration;



var usrIncFrms = 20;

var incFrm = usrIncFrms * frmDur;


// Make Markers (Frames)

tm = tm + startTime;

while (tm <= endTime - incFrm){

marker.setValueAtTime(tm, mkrVal);

for (var tm = (tm + incFrm); tm<=marker.numKeys; tm++);
{
for (var nbrMkrs = 1; nbrMkrs<=marker.numKeys; nbrMkrs++);
}

marker.setValueAtTime(tm, mkrVal);

}//End While



//EOF

Image


I then went back to the original script written in seconds and set the increment to a decimal value of ".5" and noticed I was having an issue with that script as well:

Image


If anyone can shed some light on this, I'd appreciate it.

TIA
nab
Posts: 203
Joined: November 29th, 2005, 3:00 am
Location: Royan
Contact:

Only one loop is required, something like this:

Code: Select all

var usrIncSec = 0.5; // seconds

var layer = app.project.activeItem.selectedLayers[0];
app.beginUndoGroup("Add Markers");
for (var t = layer.inPoint + usrIncSec; t <= layer.outPoint - usrIncSec; t+=usrIncSec)
{
	layer.Marker.setValueAtTime(t, new MarkerValue(""));
}
app.endUndoGroup();
scottmiles
Posts: 2
Joined: January 14th, 2010, 6:45 pm
Location: Seattle, Washington - USA

Thanks Nab:

It worked like a charm.
Post Reply