Select between markers no longer working
Title
Select between markers no longer working
What do you expect to happen when you run the script/macro?
Supposed to select between two markers in PT timeline. Worked before Avid changed the mem location window. Now it tells me that my markers don't exist even though I'm sure the names are right.
Are you seeing an error?
12.02.2024 15:18:38.45 [Backend]: JavaScript error with InnerException: null !! Command Error: Select from TOP to END [user:ckxutogx50005r310sz5proau:cky23yqla0002ur10rfypsd0c]: Could not find a memory location by name 'TOP' (Select from TOP to END line 40)
Pops up in that little top right SF window
What happens when you run this script?
Just the error, nothing else
How were you running this script?
I used a keyboard shortcut within the target app
How important is this issue to you?
5
Details
{ "inputExpected": "Supposed to select between two markers in PT timeline. Worked before Avid changed the mem location window. Now it tells me that my markers don't exist even though I'm sure the names are right.", "inputIsError": true, "inputError": "12.02.2024 15:18:38.45 [Backend]: JavaScript error with InnerException: null\n!! Command Error: Select from TOP to END [user:ckxutogx50005r310sz5proau:cky23yqla0002ur10rfypsd0c]:\nCould not find a memory location by name 'TOP'\n(Select from TOP to END line 40) \n\nPops up in that little top right SF window", "inputWhatHappens": "Just the error, nothing else", "inputHowRun": { "key": "-Mpfwh4RkPLb2LPwjePT", "title": "I used a keyboard shortcut within the target app" }, "inputImportance": 5, "inputTitle": "Select between markers no longer working" }
Source
sf.ui.proTools.appActivateMainWindow();
sf.ui.proTools.invalidate();
function getMemoryLocations() {
sf.ui.proTools.appActivate();
sf.ui.proTools.mainWindow.elementRaise();
var i = 0;
while (i++ < 5) {
if (!sf.ui.proTools.memoryLocationsWindow.invalidate().exists) {
sf.ui.proTools.getMenuItem('Window', 'Memory Locations').elementClick({}, 'Could not click to open Memory Locations window');
sf.ui.proTools.memoryLocationsWindow.elementWaitFor();
}
var table = sf.ui.proTools.memoryLocationsWindow.invalidate().tables[1];
if (!table.exists) {
sf.ui.proTools.memoryLocationsWindow.windowClose();
}
}
if (!table.exists) throw 'Could not find memory locations table';
var seed = (new Date).valueOf();
var items = [];
table.childrenByRole("AXRow").forEach(function (item, i) {
var num = item.children[1].children.first.title.value;
var text = item.children[2].children.first.title.value;
if (num === null || text === null) return;
items.push({
num,
text,
});
});
return items;
}
function selectBetweenMemoryLocationsByName({ name1, name2 }) {
let locations = getMemoryLocations();
let location1 = locations.find(l => l.text === name1);
let location2 = locations.find(l => l.text === name2);
if (!location1) throw `Could not find a memory location by name '${name1}'`;
if (!location2) throw `Could not find a memory location by name '${name2}'`;
let locNum1 = Number(location1.num.trim());
let locNum2 = Number(location2.num.trim());
sf.ui.proTools.memoryLocationsGoto({
memoryLocationNumber: locNum1,
useKeyboard: true,
});
sf.ui.proTools.memoryLocationsGoto({
memoryLocationNumber: locNum2,
extendSelection: true,
useKeyboard: true,
});
}
selectBetweenMemoryLocationsByName({
name1: 'TOP',
name2: 'END',
});
Links
User UID: FBLa5v2xxqUfy8frXnCX930H3JC2
Feedback Key: sffeedback:FBLa5v2xxqUfy8frXnCX930H3JC2:-NqTyaPQUwer1TtaEZXw
Feedback ZIP: b7bhxv45ceQYuRUg1KZw8SJaiIUIY1H9VAOAJtXjv4RWb7t/AEiJixyNOeEZpVOOkmq5Xf+bSVmsqf557amfwAEFnTK87jhMml8f0qKykrjxp8HGFDpO0fC3E+l/L02z+Niw39ago3uLlGynhUQUtqoxHKCV8Yp8NH8SylKcRmPF6NsVKrHEPQ1nxXYUc7Ne0PJolzv6Y39ACPBCIBU1GweoZAi6MfNHGttxm63d6A50FtGBmhp8But08QQY9BIquI98pD5q2pbdGTV7YeqmCKgTVRHJV9GD1KSNR11lPJsmbJQL8gl6MfjPufRFz4qP75YItuUw3W6R878ybAVt6Q==
- Raphael Sepulveda @raphaelsepulveda2024-02-12 21:21:30.689Z
@Eli_Crews, thanks for posting this here!
Here's your script working in PT 2023.12:
sf.ui.proTools.appActivateMainWindow(); sf.ui.proTools.invalidate(); function getMemoryLocations() { sf.ui.proTools.appActivate(); sf.ui.proTools.mainWindow.elementRaise(); var i = 0; while (i++ < 5) { if (!sf.ui.proTools.memoryLocationsWindow.invalidate().exists) { sf.ui.proTools.getMenuItem('Window', 'Memory Locations').elementClick({}, 'Could not click to open Memory Locations window'); sf.ui.proTools.memoryLocationsWindow.elementWaitFor(); } var table = sf.ui.proTools.memoryLocationsWindow.invalidate().tables[1]; if (!table.exists) { sf.ui.proTools.memoryLocationsWindow.windowClose(); } } if (!table.exists) throw 'Could not find memory locations table'; var seed = (new Date).valueOf(); var items = []; table.childrenByRole("AXRow").forEach(function (item, i) { var num = item.children[2].children.first.title.value; var text = item.children[3].children.first.title.value; if (num === null || text === null) return; if (num.startsWith("Selected. ")) { num = num.replace("Selected. ", ""); } if (text.startsWith("Selected. ")) { text = text.replace("Selected. ", ""); } items.push({ num, text, }); }); return items; } function selectBetweenMemoryLocationsByName({ name1, name2 }) { let locations = getMemoryLocations(); let location1 = locations.find(l => l.text === name1); let location2 = locations.find(l => l.text === name2); if (!location1) throw `Could not find a memory location by name '${name1}'`; if (!location2) throw `Could not find a memory location by name '${name2}'`; let locNum1 = Number(location1.num.trim()); let locNum2 = Number(location2.num.trim()); sf.ui.proTools.memoryLocationsGoto({ memoryLocationNumber: locNum1, useKeyboard: true, }); sf.ui.proTools.memoryLocationsGoto({ memoryLocationNumber: locNum2, extendSelection: true, useKeyboard: true, }); } selectBetweenMemoryLocationsByName({ name1: 'TOP', name2: 'END', });
The main change to get this functional again was just upping the index on these two lines.
From this:var num = item.children[1].children.first.title.value; var text = item.children[2].children.first.title.value;
To this:
var num = item.children[2].children.first.title.value; var text = item.children[3].children.first.title.value;
Besides that, I added a bit of code in the
getMemoryLocations
function to prevent an error from happening if one of the memory locations is currently selected.Let me know how it goes on your end!
- EEli Crews @Eli_Crews
Yes, that works! Amazing, thank you!
- In reply toraphaelsepulveda⬆:EEli Crews @Eli_Crews
Sadly, this is only working intermittently. About half the time, it does what I expect, and selects from the TOP to the END markers, but the other half of the time it starts the selection at the TOP and the back end of the selection is some random place in the timeline, not even on a marker. Can't figure out any rhyme or reason to it, but when it happens it keeps selecting the same out point of the selection for a while. For one song, it was a 3:37 long selection, for another, a 3:46...
Raphael Sepulveda @raphaelsepulveda2024-02-22 00:25:54.232Z
@Eli_Crews, sorry to hear that!
We can definitely dig into the details to figure out exactly what's going wrong, but before we do that, let's try another approach.
There have been some behind-the-scenes developments since your original script was written (ie we can now grab the memory locations via the PT SDK), so I'd be interested to see if revamping it fixes the issues you're seeing. Here it is:
function selectBetweenMemoryLocationsByName({ memLocNameA, memLocNameB }) { const memLocA = sf.app.proTools.memoryLocations.invalidate().allItems.find(memoryLocation => memoryLocation.name === memLocNameA); const memLocB = sf.app.proTools.memoryLocations.invalidate().allItems.reverse().find(memoryLocation => memoryLocation.name === memLocNameB); if (!memLocA) throw `Could not find a memory location by name '${memLocNameA}'`; if (!memLocB) throw `Could not find a memory location by name '${memLocNameB}'`; sf.app.proTools.selectMemoryLocation({ number: memLocA.number }); sf.ui.proTools.memoryLocationsGoto({ memoryLocationNumber: memLocB.number, extendSelection: true }); } selectBetweenMemoryLocationsByName({ memLocNameA: 'TOP', memLocNameB: 'END', });
Fingers crossed 🤞🏼
- EEli Crews @Eli_Crews
So far, so good, thank you!!