I am a little tired and slow today so you will have to forgive me.
I need to add a marker to a layer and cannot figure the process out. The manual has an example, but I cannot get it to work. This is what the docs say:
To set a marker that says “Fade Up†at the 2 second mark:
var myMarker = new Marker("Fade Up");
myLayer.property("Marker").setValueAtTime(2, myMarker);
I've tried adding a layer item to attach the property to like:
var myLayer = app.project.item(1).layer(1);
var myMarker = new myLayer.property.Marker("Fade Up");
I keep getting the error that the property does not have a constructor.
Thanks.
Add Marker
Moderator: Paul Tuersley
Did you take a look at Paul Tuersley's script "split layer at markers" in the scripts library? I think it works with markers in several ways, so you could probably learn something from taking a look at it.
Maybe Paul can elaborate?
Alex
Maybe Paul can elaborate?
Alex
I did look at Paul's script, but he never creates a marker. I'm sure it's something simple and basic and I'm looking right past it. My scripting skills are still in the "hack" status.
Thanks.
Thanks.
-
- Posts: 704
- Joined: June 5th, 2004, 7:59 am
- Location: London, UK
Took me a while to figure this out too, it should be:
var myMarker = new MarkerValue("Fade Up");
myLayer.Marker.setValueAtTime(2, myMarker);
Also, you can add blank markers using:
myLayer.Marker.addKey(2);
Paul T
var myMarker = new MarkerValue("Fade Up");
myLayer.Marker.setValueAtTime(2, myMarker);
Also, you can add blank markers using:
myLayer.Marker.addKey(2);
Paul T
Thanks Paul, the first snippet you gave worked. I couldn't get the blank marker to work though. I don't really need it, it doesn't hurt anything to name the markers.
This site is great, I hope we can get more people sharing ideas and scripts!
Take care.
This site is great, I hope we can get more people sharing ideas and scripts!
Take care.
Here is an alternative syntax (probably a bit longer than Paul's)
The following script will set a new marker "Fade Up" at time 0:
// assume app.project.item(1) is CompItem, and has 1 layer.
var myMarker = new Marker("Fade Up");
app.project.item(1).layer(1).property("marker").setValueAtTime(0, myMarker);
If you'd like to set a new marker at current time, do this:
// assume app.project.item(1) is CompItem, and has 1 layer.
var myMarker = new Marker("Fade Up");
app.project.item(1).layer(1).property("marker").setValueAtTime(app.project.item(1).layer(1).time, myMarker);
The following script will set a new marker "Fade Up" at time 0:
// assume app.project.item(1) is CompItem, and has 1 layer.
var myMarker = new Marker("Fade Up");
app.project.item(1).layer(1).property("marker").setValueAtTime(0, myMarker);
If you'd like to set a new marker at current time, do this:
// assume app.project.item(1) is CompItem, and has 1 layer.
var myMarker = new Marker("Fade Up");
app.project.item(1).layer(1).property("marker").setValueAtTime(app.project.item(1).layer(1).time, myMarker);
For some unknown reason, the empty marker script works now. I couldn't get it to work when I tried a while back. I gave it another shot today and it worked. Go figure.
After you make an empty marker, is there a way to go back and give it a name or change it's time value? I haven't delved into that much but I was just curious.
After you make an empty marker, is there a way to go back and give it a name or change it's time value? I haven't delved into that much but I was just curious.
-
- Posts: 704
- Joined: June 5th, 2004, 7:59 am
- Location: London, UK
Here's some good stuff from Keiko on using markers:
There are 2 example in 1 script. example 1 will change value (comment) of markers.
You can change any other markerValue property with same manner.
example 2 will snap markers to nearest second to time. This is a bit tricky. If I call
setValueAtTime with the "nearest second", I actually create a new marker at new
times. So I store data first, remove original markers and re-set by using data I stored.
I thought markerKeyTime = 10 will set time to 10, but it does not work.
-keiko
There are 2 example in 1 script. example 1 will change value (comment) of markers.
You can change any other markerValue property with same manner.
example 2 will snap markers to nearest second to time. This is a bit tricky. If I call
setValueAtTime with the "nearest second", I actually create a new marker at new
times. So I store data first, remove original markers and re-set by using data I stored.
I thought markerKeyTime = 10 will set time to 10, but it does not work.
-keiko
Code: Select all
{
// assume you have app.project.item(1) is comp
// and comp.layer(1) is layer with multiple markers.
// get markers
var markers = app.project.item(1).layer(1).property("marker");
// example 1:
// change existing markers
var undoStr = "Change marker comments";
app.beginUndoGroup(undoStr);
for(var i = 1; i <= markers.numKeys; i++) {
// get MarkerValue of each marker
var markerVal = markers.keyValue(i);
// set MarkerValue.comment
markerVal.comment = i + " marker";
// set marker with new MarkerValue
markers.setValueAtKey(i, markerVal);
}
app.endUndoGroup();
// example 2:
// snap all markers to nearest second in time
undoStr = "Change marker time";
var newMarkers = new Array();
var newTimes = new Array();
app.beginUndoGroup(undoStr);
for(var i = markers.numKeys; i >= 1; i--) {
// get MarkerValue of each marker
var markerVal = markers.keyValue(i);
newMarkers[newMarkers.length] = markerVal;
// set time to nearest second
var markerKeyTime = markers.keyTime(i);
var newMarkerTime = Math.round(markerKeyTime);
newTimes[newTimes.length] = newMarkerTime;
// remove original markers
markers.removeKey(i);
}
// add new markers with new value.
for(var i = 0; i < newMarkers.length; i++) {
markers.setValueAtTime(newTimes[i], newMarkers[i]);
}
app.endUndoGroup();
}