Activity › Forums › Adobe After Effects Expressions › Convert Text Source Keyframes to Marker layers with same text
-
Convert Text Source Keyframes to Marker layers with same text
Posted by Craig Trayler on March 7, 2022 at 4:20 pmHi CC, I have a very long project that on top layer has a single text layer that contains 100’s of Source text keyframes (used for subtitles).
I am looking for a way/script that would take the selected text layer in the active comp, add a marker point on the same frame as the source text keyframe, and then copy the text in that keyframe and paste it into each marker comment.
I have seen some code to create markers based on keyframes, but nothing about pulling text data from source text keyframes any adding to marker comments. I love to learn but this has stumped me.
Thanks again for any help on this one.
– Craigabbas seyyedi replied 3 years, 3 months ago 3 Members · 12 Replies -
12 Replies
-
Dan Ebberts
March 7, 2022 at 5:25 pmThis should get you close:
function keyframesToMarkers(){
var myComp = app.project.activeItem;
if (myComp == null || ! (myComp instanceof CompItem)){
alert ("No comp active.");
return;
}
if (myComp.selectedLayers.length == 0){
alert ("No layer selected.");
return;
}
var myLayer = myComp.selectedLayers[0];
if ( ! (myLayer instanceof TextLayer)){
alert ("Selected layer is not a text layer.");
return;
}
var markerVal = new MarkerValue("");
var mySourceText = myLayer.property("ADBE Text Properties").property("ADBE Text Document");
var myTextDoc;
for (var i = 1; i <= mySourceText.numKeys; i ++){
myTextDoc = mySourceText.keyValue(i);
markerVal.comment = myTextDoc.text;
myLayer.property("Marker").setValueAtTime(mySourceText.keyTime(i),markerVal);
}
}
keyframesToMarkers();
-
Craig Trayler
March 7, 2022 at 5:54 pmThank you Dan! Your works are just great. This worked perfectly.
One more thing if I may, I have only just noticed some Source text keyframes were purposely made empty/Blank/containing not text, is there a line of code you can add to check that if the Keyframe is empty, to ignore making a marker and move onto the next one? -
Dan Ebberts
March 7, 2022 at 6:52 pmJust put this line:
if (myTextDoc.text == "") continue;
right before this one:
markerVal.comment = myTextDoc.text;
-
Craig Trayler
June 13, 2022 at 11:23 amHi Dan or anyone who can assist a little more.
Everything is great, but wanted to know if there is also a way to add duration of each created marker to extend it’s length until the next following text source keyframe?I would venture a guess that there needs to be an If function to check if there is a next keyframe to counter an error for the very last keyframe.
Thanks in advance,
Craig -
Dan Ebberts
June 13, 2022 at 2:19 pmLike this, I guess:
function keyframesToMarkers(){
var myComp = app.project.activeItem;
if (myComp == null || ! (myComp instanceof CompItem)){
alert ("No comp active.");
return;
}
if (myComp.selectedLayers.length == 0){
alert ("No layer selected.");
return;
}
var myLayer = myComp.selectedLayers[0];
if ( ! (myLayer instanceof TextLayer)){
alert ("Selected layer is not a text layer.");
return;
}
var markerVal = new MarkerValue("");
var mySourceText = myLayer.property("ADBE Text Properties").property("ADBE Text Document");
var myTextDoc;
for (var i = 1; i <= mySourceText.numKeys; i ++){
myTextDoc = mySourceText.keyValue(i);
if (myTextDoc.text == "") continue;
markerVal.comment = myTextDoc.text;
if (i < mySourceText.numKeys){
markerVal.duration = mySourceText.keyTime(i+1) - mySourceText.keyTime(i);
}else{
markerVal.duration = 0;
}
myLayer.property("Marker").setValueAtTime(mySourceText.keyTime(i),markerVal);
}
}
keyframesToMarkers();
-
abbas seyyedi
February 14, 2023 at 4:59 pmWhat if I want the opposite? For example, the markers become keyframes in the source text
-
Dan Ebberts
February 14, 2023 at 5:20 pmSomething like this, probably:
function markersToKeyframes(){
var myComp = app.project.activeItem;
if (myComp == null || ! (myComp instanceof CompItem)){
alert ("No comp active.");
return;
}
if (myComp.selectedLayers.length == 0){
alert ("No layer selected.");
return;
}
var myLayer = myComp.selectedLayers[0];
if ( ! (myLayer instanceof TextLayer)){
alert ("Selected layer is not a text layer.");
return;
}
var mySourceText = myLayer.property("ADBE Text Properties").property("ADBE Text Document");
var myTextDoc = mySourceText.value;
var myMarker = myLayer.property("Marker");
var myMarkerVal = new MarkerValue("");
var myMarkerTime;
for (var i = 1; i <= myMarker.numKeys; i ++){
myMarkerVal = myMarker.keyValue(i);
myMarkerTime = myMarker.keyTime(i);
myTextDoc.text = myMarkerVal.comment;
if (myTextDoc.text == "") continue;
mySourceText.setValueAtTime(myMarkerTime,myTextDoc)
}
}
markersToKeyframes(); -
abbas seyyedi
February 15, 2023 at 9:19 amThanks Dan. I ran the code. It runs without error, but no key is added in the source text layer
-
abbas seyyedi
February 15, 2023 at 9:29 amLet’s assume that the markers are expanded and we want to convert the beginning of the marker time into a key
Reply to this Discussion! Login or Sign Up