Skip to main content
Known Participant
March 4, 2023
Answered

Script that splits a layer into multiple layers at marked points?

  • March 4, 2023
  • 1 reply
  • 636 views

Hey there,

I have an audio file made up of individual 'quotes' that I need to split a bunch of times. I'm wondering, if I manually mark the portions of the layer that needs to be divided, is there a script that can use these markers and dice up my layer into the the portions I need?

 

Thank you

This topic has been closed for replies.
Correct answer Dan Ebberts

Try this:

if (app.project.activeItem && app.project.activeItem instanceof CompItem){ 
	var myComp = app.project.activeItem;
	if (myComp.selectedLayers.length > 0){
		var myLayer = myComp.selectedLayers[0];
		for (var i = 1; i <= myLayer.property("marker").numKeys; i++){
			var newLayer = myLayer.duplicate();
			newLayer.inPoint = myLayer.property("marker").keyTime(i);
			if (i < myLayer.property("marker").numKeys){
				newLayer.outPoint = myLayer.property("marker").keyTime(i+1);
			}
		}
		if (myLayer.property("marker").numKeys > 0){
			myLayer.outPoint = myLayer.property("marker").keyTime(1);
		}
	}
}

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
March 4, 2023

Try this:

if (app.project.activeItem && app.project.activeItem instanceof CompItem){ 
	var myComp = app.project.activeItem;
	if (myComp.selectedLayers.length > 0){
		var myLayer = myComp.selectedLayers[0];
		for (var i = 1; i <= myLayer.property("marker").numKeys; i++){
			var newLayer = myLayer.duplicate();
			newLayer.inPoint = myLayer.property("marker").keyTime(i);
			if (i < myLayer.property("marker").numKeys){
				newLayer.outPoint = myLayer.property("marker").keyTime(i+1);
			}
		}
		if (myLayer.property("marker").numKeys > 0){
			myLayer.outPoint = myLayer.property("marker").keyTime(1);
		}
	}
}