Simple script. Create a marker for each selected clip with a specific name
Hi all,
I'm new to coding. I'm trying to create a macro / script that will create a new marker with a specific name, at the in points of each selected clip.
I managed to get to the next script, selection seems to work fine, but it does not create the actual markers (though I do see the marker window open).
Any help or directions will be greatly appreciated!
sf.ui.proTools.appActivateMainWindow();
function createMarker(){
sf.ui.proTools.memoryLocationsCreate({
name: "p"
})
};
sf.ui.proTools.clipDoForEachSelectedClip({
action: clip => createMarker()
})
- Chad Wahlbrink @Chad2025-04-14 20:44:20.132Z
Hi, @FACUNDO_GZ,
Great question! For memory locations, it's best to be able to provide a memory location number for each memory location you create.
So in script form, this is what I would do:
sf.ui.proTools.appActivateMainWindow(); // Find the highest Memory Location Number in the session let highestMemoryLocationNumber = Math.max(...sf.app.proTools.memoryLocations.invalidate().allItems.map(memLoc => memLoc.number)); /* Set the nextMemoryLocationNumber to the (highestMemoryLocationNumber + 1) if any other memory Locations exist in this session. Otherwise, set nextMemoryLocationNumber to 1. */ let nextMemoryLocationNumber = highestMemoryLocationNumber ? highestMemoryLocationNumber + 1 : 1; // Do for each clip sf.ui.proTools.clipDoForEachSelectedClip({ action: () => { // Create a Memory Location sf.app.proTools.createMemoryLocation({number:nextMemoryLocationNumber, name: 'p', startTime: sf.app.proTools.getTimelineSelection().inTime}); // add 1 to the nextMemoryLocationNumber nextMemoryLocationNumber++; } })
I'm using some
sf.app.proTools
calls to query the Pro Tools SDK for the current memory location numbers in the session, then determining the following memory location number (either one or the next highest number).Finally, I'm setting up the "call back action" in the
sf.ui.proTools.clipDoForEachSelectedClip()
method a bit differently. In your script, you were calling it like this:sf.ui.proTools.clipDoForEachSelectedClip({ action: clip => createMarker() })
For it to run correctly, you would only need to reference the name of the function you had created like this:
sf.ui.proTools.clipDoForEachSelectedClip({ action: createMarker })
However, because your original script was assigning the same number to each memory location, it would only end up adding a single memory location to the last clip in the selection.
The callback function in my script is formatted like this:
// Do for each clip sf.ui.proTools.clipDoForEachSelectedClip({ action: () => { // Create a Memory Location sf.app.proTools.createMemoryLocation({number:nextMemoryLocationNumber, name: 'p', startTime: sf.app.proTools.getTimelineSelection().inTime}); // add 1 to the nextMemoryLocationNumber nextMemoryLocationNumber++; } })
This is a different way of declaring a function without defining it elsewhere in the script.
I hope that helps!
Cheers,
Chad - FIn reply toFACUNDO_GZ⬆:FACUNDO GZ @FACUNDO_GZ
Chad,
I can't thank you enough for such a detailed answer.
I learned a lot from it.
I'd like to investigate more to better understand the way that you're declaring the function and it's synthax (ie. how you set it to increment and name the markers within a same block). Any online material that you think will help (if you have the time and patience of course) ?
Thank you!