Automating importing session data & video.
Hi All,
Has anyone done something similar for importing session data & video?
Whenever I import an AAF or a Video into my template I’ll have to go through the file directory to select the correct folder that the AAF & Video is in because PT always defaults it to the last used directory.
I always keep my AAF & Video files in a folder called “Original Sessions & files > v1” in the same folder the current PT session is in. Is there a way to have pro tools look for the AAF & Video in the same folder the current session is in?
If it’s possible, can it be integrated with these steps as a script so that the AAF and video will be imported with a push of a button?
Steps would somewhat be like:
- Select last track in the session
- Go to timecode 10:00:00:00
- File > Import > Session Data...
- Select “Original Sessions & Files” folder from current session
- Wait for the user to click "Open" just to be sure the correct AAF is being selected.
- Click Ok when import session data window opens.
- Wait until files are loaded and restore.
- File > Import > Video...
- Select “Original Sessions & Files” folder from current session.
- Wait for the user to click "Open"
- When “Video Import Options” window appears, select “New Track”, “Selection” and click “Ok”.
*Pause script if “Session Notes” window appears.
Thanks in advance!
Linked from:
- Christian Scheuer @chrscheuer2020-04-15 11:37:56.668Z
Hi Daniel.
Some great stuff here.
You should start with this script to understand more about how to script opening the Import Session Data window and selecting a particular PTX file:
https://forum.soundflow.org/-1381#post-4Then once you've got that half of your workflow working, let's go from there.
- DDaniel Lee @Daniel_Lee
Hi Chrisitan,
Thanks!
So far this is where i'm at so far. Opening the import session data window, and navigating to the correct folder directory.
However, i can't seem to tell the script to stop until i select a .AAF file.function navigateToInDialog(win, path) { //Open the Go to... sheet sf.keyboard.type({ text: '/' }); //Wait for the sheet to appear var sheet = win.sheets.first.elementWaitFor({ timeout: 500 }, 'Could not find "Go to" sheet in the Save/Open dialog').element; //Set the value of the combo box sheet.comboBoxes.first.value.value = path; //Press OK sheet.buttons.whoseTitle.is('Go').first.elementClick({}, 'Could not click "Go"'); //Wait for sheet to close win.sheets.first.elementWaitFor({ waitForNoElement: true, timeout: 500 }, '"Go to" sheet didn\'t close in time'); } function importSession(sessionPath) { // Open up Import Session Data sf.ui.proTools.menuClick({ menuPath: ['File', 'Import', 'Session Data...'] }); // Wait for window to open var importWin = sf.ui.proTools.windows.whoseTitle.is('Open').first; // Navigate to folder navigateToInDialog(importWin, sessionPath); // Click Open importWin.buttons.whoseTitle.is('Open').first.elementClick(); // Wait for import window to close importWin.elementWaitFor({ waitForNoElement: true }); } //path of current session var folderPath = (sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/')) var originalFilesPath = folderPath + "/Original Sessions & Files" function main() { //Navigate to folder of current session > Original Sessions & Files Folder importSession(originalFilesPath); //Wait for Import Session Data var importSessionWin = sf.ui.proTools.windows.whoseTitle.is('Import Session Data').first.elementWaitFor().element; }); //Click OK //importSessionWin.getFirstWithTitle("OK").elementClick(); } main();
Christian Scheuer @chrscheuer2020-04-15 13:27:32.157Z
Great WIP.
I think I would automate this slightly differently. I would use
sf.interaction.popupSearch
orsf.interaction.selectFile
to let the user select the correct PTX file to open first, and then let the script automate everything else.IMO it's the best user experience since the user gets asked immediately - and then the script performs the rest, which means the user won't have to supervise the automation.
It's also easier to script :)
Do you need any pointers to get
sf.interaction.popupSearch
orsf.interaction.selectFile
to work?Christian Scheuer @chrscheuer2020-04-15 13:28:15.331Z
You can see the docs for them here (not sure how much they help, but just in case):
https://soundflow.org/docs/api/interfaces/automationrootinteractionapi#popupsearch
https://soundflow.org/docs/api/interfaces/automationrootinteractionapi#selectfileChristian Scheuer @chrscheuer2020-04-15 13:30:32.488Z
I would do this:
function askForPtxFile() { //path of current session var folderPath = (sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/')) var originalFilesPath = folderPath + "/Original Sessions & Files"; var selectedPath = sf.interaction.popupSearch({ items: sf.file.directoryGetFiles({ path: originalFilesPath, searchPattern: '*.ptx' }).paths.map(p => ({ name: p.split('/').slice(-1)[0], })), }).item.name; return selectedPath; } var ptxPath = askForPtxFile(); importSession(ptxPath);
- DDaniel Lee @Daniel_Lee
Thanks Christian! Been fiddling around with it the past 2 hours. But this is the error i'm getting.
<info> [Backend]: Error in line 50: ClickButtonAction requires UIElement (ClickButtonAction)
I've managed to do steps 1 & 2 (from OP). As for the popup search, I'm able to see the .aaf file.
But is there a way where i can see folders and then navigate to the aaf from the same search? Eg. click v1 folder and select the .aaf in that folder.
This is what i have so far.
function selectLastTack() { //Select last track in session var lastTrackName = sf.ui.proTools.trackNames.slice(-1)[0]; sf.ui.proTools.trackSelectByName({ names: [lastTrackName] }) sf.ui.proTools.selectedTrack.trackScrollToView(); } selectLastTack(); function setTimecode() { sf.ui.proTools.mainCounterSetValue({ targetValue: "Timecode", }); //set timecode to be 10:00:00:00 sf.ui.proTools.selectionSetTimecode({ mainCounter: "10:00:00:00", }); } setTimecode(); function askForPtxFile() { //path of current session var folderPath = (sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/')) var originalFilesPath = folderPath + "/Original Sessions & Files"; var selectedPath = sf.interaction.popupSearch({ items: sf.file.directoryGetFiles({ path: originalFilesPath, searchPattern: '*.aaf' }).paths.map(p => ({ name: p.split('/').slice(-1)[0], })), }).item.name; return selectedPath; } function importSession(sessionPath) { // Open up Import Session Data sf.ui.proTools.menuClick({ menuPath: ['File', 'Import', 'Session Data...'] }); // Wait for window to open var importWin = sf.ui.proTools.windows.whoseTitle.is('Open').first; // Navigate to folder sf.interaction.selectFile; // Click Open importWin.buttons.whoseTitle.is('Open').first.elementClick(); // Wait for import window to close importWin.elementWaitFor({ waitForNoElement: true }); } //Click OK //importSessionWin.getFirstWithTitle("OK").elementClick(); //} var ptxPath = askForPtxFile(); importSession(ptxPath); ;
Christian Scheuer @chrscheuer2020-04-15 16:04:11.152Z
I would change the
askForPtxFile
function to this - it will get you a list of all AAF files also in subdirectories:function askForPtxFile() { //path of current session var folderPath = (sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/')) var originalFilesPath = folderPath + "/Original Sessions & Files"; var aafFileCandidates = sf.file.directoryGetFiles({ path: originalFilesPath, isRecursive: true, searchPattern: '*.aaf' }).paths; var selectedPath = sf.interaction.popupSearch({ items: aafFileCandidates.map(p => ({ name: p.replace(originalFilesPath, '').substring(1), })), }).item.name; return selectedPath; }
Christian Scheuer @chrscheuer2020-04-15 16:05:13.873Z
Alternatively, if you want a more regular interface for selecting the file (although slightly more mouse clicking is needed this way), you could do this:
function askForPtxFile() { //path of current session var folderPath = (sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/')) var originalFilesPath = folderPath + "/Original Sessions & Files"; var selectedPath = sf.interaction.selectFile({ defaultLocation: originalFilesPath, }).path; return selectedPath; }
- In reply tochrscheuer⬆:DDaniel Lee @Daniel_Lee
Wow this is perfect!
Sorry Christian i tried serveral ways but after selecting the AAF, i can't get it to save the path of the selected AAF, go to the import session data window, go to the path.
This is the error that I'm getting.
<info> [Backend]: Error in line 55: ClickButtonAction requires UIElement (ClickButtonAction)
This is the full code.
function selectLastTack() { //Select last track in session var lastTrackName = sf.ui.proTools.trackNames.slice(-1)[0]; sf.ui.proTools.trackSelectByName({ names: [lastTrackName] }) sf.ui.proTools.selectedTrack.trackScrollToView(); } selectLastTack(); function setTimecode() { sf.ui.proTools.mainCounterSetValue({ targetValue: "Timecode", }); //set timecode to be 10:00:00:00 sf.ui.proTools.selectionSetTimecode({ mainCounter: "10:00:00:00", }); } setTimecode(); function askForPtxFile() { //path of current session var folderPath = (sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/')) var originalFilesPath = folderPath + "/Original Sessions & Files"; var aafFileCandidates = sf.file.directoryGetFiles({ path: originalFilesPath, isRecursive: true, searchPattern: '*.aaf' }).paths; var selectedPath = sf.interaction.popupSearch({ items: aafFileCandidates.map(p => ({ name: p.replace(originalFilesPath, '').substring(1), })), }).item.name; return selectedPath; } function importSession(sessionPath) { // Open up Import Session Data sf.ui.proTools.menuClick({ menuPath: ['File', 'Import', 'Session Data...'] }); // Wait for window to open var importWin = sf.ui.proTools.windows.whoseTitle.is('Open').first; // Navigate to folder sf.interaction.selectFile; // Click Open importWin.buttons.whoseTitle.is('Open').first.elementClick(); // Wait for import window to close importWin.elementWaitFor({ waitForNoElement: true }); } //Click OK //importSessionWin.getFirstWithTitle("OK").elementClick(); //} var ptxPath = askForPtxFile(); importSession(ptxPath);
Christian Scheuer @chrscheuer2020-04-15 17:12:25.696Z
Oh, I'm sorry that's my bad:
Change it to this:
function askForPtxFile() { //path of current session var folderPath = (sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/')) var originalFilesPath = folderPath + "/Original Sessions & Files"; var aafFileCandidates = sf.file.directoryGetFiles({ path: originalFilesPath, isRecursive: true, searchPattern: '*.aaf' }).paths; var selectedPath = sf.interaction.popupSearch({ items: aafFileCandidates.map(p => ({ name: p.replace(originalFilesPath, '').substring(1), path: p, })), }).item.path; return selectedPath; }
- DDaniel Lee @Daniel_Lee
Ok, I've changed that function but still can't get to the import session data window.
Or should they be two separate scripts?
- Script to select the path.
- Run the import session data script.
Christian Scheuer @chrscheuer2020-04-15 17:42:24.333Z
Ah - you've changed the
importSession
function and inserted this:// Navigate to folder sf.interaction.selectFile;
Which doesn't do anything.
Try this - I've reorganized and cleaned up a bit:
function navigateToInDialog(win, path) { //Open the Go to... sheet sf.keyboard.type({ text: '/' }); //Wait for the sheet to appear var sheet = win.sheets.first.elementWaitFor({ timeout: 500 }, 'Could not find "Go to" sheet in the Save/Open dialog').element; //Set the value of the combo box sheet.comboBoxes.first.value.value = path; //Press OK sheet.buttons.whoseTitle.is('Go').first.elementClick({}, 'Could not click "Go"'); //Wait for sheet to close win.sheets.first.elementWaitFor({ waitForNoElement: true, timeout: 500 }, '"Go to" sheet didn\'t close in time'); } function importSession(sessionPath) { // Open up Import Session Data sf.ui.proTools.menuClick({ menuPath: ['File', 'Import', 'Session Data...'] }); // Wait for window to open var importWin = sf.ui.proTools.windows.whoseTitle.is('Open').first; // Navigate to folder navigateToInDialog(importWin, sessionPath); // Click Open importWin.buttons.whoseTitle.is('Open').first.elementClick(); // Wait for import window to close importWin.elementWaitFor({ waitForNoElement: true }); } function selectLastTack() { //Select last track in session var lastTrackName = sf.ui.proTools.trackNames.slice(-1)[0]; sf.ui.proTools.trackSelectByName({ names: [lastTrackName] }) sf.ui.proTools.selectedTrack.trackScrollToView(); } function setTimecode(value) { sf.ui.proTools.mainCounterSetValue({ targetValue: "Timecode", }); sf.ui.proTools.selectionSetTimecode({ mainCounter: value, }); } function askForAafFile(subFolderName) { //path of current session var folderPath = (sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/')) var originalFilesPath = folderPath + "/" + subFolderName; var aafFileCandidates = sf.file.directoryGetFiles({ path: originalFilesPath, isRecursive: true, searchPattern: '*.aaf' }).paths; var selectedPath = sf.interaction.popupSearch({ items: aafFileCandidates.map(p => ({ name: p.replace(originalFilesPath, '').substring(1), })), }).item.name; return selectedPath; } function main() { selectLastTack(); setTimecode("10:00:00:00"); var ptxPath = askForAafFile("Original Sessions & Files"); importSession(ptxPath); } main();
- DDaniel Lee @Daniel_Lee
Thanks Christian. Sorry my bad, was trying a different bunch of stuff to get the import function to work.
This is the error i'm getting with the new code. The import session data window is still not showing after selecting the path.
16.04.2020 01:50:41.14 <info> [Backend]: >> Command: Test Script [user:ck7nhzqn5000702100w8p9uaz:ck91d6te9000cvj10y22o7xqa] 16.04.2020 01:50:41.40 <info> [Backend]: Clicking with mouse here: 581, 61 16.04.2020 01:50:41.52 <info> [Backend]: Succesfully set selection to: MainCounter: 10:00:00:00 Sel Start: Sel End: Sel Length: 16.04.2020 01:50:41.52 <info> [Backend]: Sending event /popup/open with subject: ToAgent... 16.04.2020 01:50:41.52 <info> [Application]: openPopupWindow 16.04.2020 01:50:42.56 <info> [Backend]: Sending event /popup/close with subject: ToAgent... 16.04.2020 01:50:42.56 <info> [Application]: closePopupWindow 16.04.2020 01:50:42.56 <info> [Application]: this.popupWindow.on(blur) 16.04.2020 01:50:42.57 <info> [Application]: this.popupWindow.on(hide) 16.04.2020 01:50:43.44 <info> [Backend]: Logging error in action (01) WaitForElementAction: Element was not found or removed after waiting 500 ms 16.04.2020 01:50:43.44 <info> [Backend]: Error in line 6: Could not find "Go to" sheet in the Save/Open dialog Element was not found or removed after waiting 500 ms (WaitForElementAction) << Command: Test Script [user:ck7nhzqn5000702100w8p9uaz:ck91d6te9000cvj10y22o7xqa]
Christian Scheuer @chrscheuer2020-04-15 18:06:08.119Z
Try this:
function navigateToInDialog(win, path) { //Open the Go to... sheet sf.keyboard.type({ text: '/' }); //Wait for the sheet to appear var sheet = win.sheets.first.elementWaitFor({ timeout: 500 }, 'Could not find "Go to" sheet in the Save/Open dialog').element; //Set the value of the combo box sheet.comboBoxes.first.value.value = path; //Press OK sheet.buttons.whoseTitle.is('Go').first.elementClick({}, 'Could not click "Go"'); //Wait for sheet to close win.sheets.first.elementWaitFor({ waitForNoElement: true, timeout: 500 }, '"Go to" sheet didn\'t close in time'); } function importSession(sessionPath) { sf.ui.proTools.appActivateMainWindow(); // Open up Import Session Data sf.ui.proTools.menuClick({ menuPath: ['File', 'Import', 'Session Data...'] }); // Wait for window to open var importWin = sf.ui.proTools.windows.whoseTitle.is('Open').first; // Navigate to folder navigateToInDialog(importWin, sessionPath); // Click Open importWin.buttons.whoseTitle.is('Open').first.elementClick(); // Wait for import window to close importWin.elementWaitFor({ waitForNoElement: true }); } function selectLastTack() { //Select last track in session var lastTrackName = sf.ui.proTools.trackNames.slice(-1)[0]; sf.ui.proTools.trackSelectByName({ names: [lastTrackName] }) sf.ui.proTools.selectedTrack.trackScrollToView(); } function setTimecode(value) { sf.ui.proTools.mainCounterSetValue({ targetValue: "Timecode", }); sf.ui.proTools.selectionSetTimecode({ mainCounter: value, }); } function askForAafFile(subFolderName) { //path of current session var folderPath = (sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/')) var originalFilesPath = folderPath + "/" + subFolderName; var aafFileCandidates = sf.file.directoryGetFiles({ path: originalFilesPath, isRecursive: true, searchPattern: '*.aaf' }).paths; var selectedPath = sf.interaction.popupSearch({ items: aafFileCandidates.map(p => ({ name: p.replace(originalFilesPath, '').substring(1), path: p, })), }).item.path; return selectedPath; } function main() { selectLastTack(); setTimecode("10:00:00:00"); var ptxPath = askForAafFile("Original Sessions & Files"); importSession(ptxPath); } main();
Christian Scheuer @chrscheuer2020-04-15 18:07:16.919Z
I think you should do the Video Import as a separate script where you then try to copy ideas from this one - and we should probably tackle that in a separate thread to keep this from growing too crazy.
- In reply tochrscheuer⬆:DDaniel Lee @Daniel_Lee
Hi Christian, yes I shall do the video import as a separate script.
My apologies for going on and on. Still trying to learn with the limited scripting knowledge that I have.The import session data dialogue works now, but I'm currently getting this error right after the "go to" sheet is closed. (Managed to get it to work once, but couldn't get it up ever since.)
Error in line 12: Could not click "Go" Error invoking AXElement: kAXErrorAttributeUnsupported (ClickButtonAction) SoundFlow.Shortcuts.AXUIElementException: kAXErrorAttributeUnsupported at SoundFlow.Shortcuts.AXUIElement.DoAction(String) + 0x9a at SoundFlow.Shortcuts.Automation.Actions.ClickButtonAction.<Execute>d__11.MoveNext() + 0x8d
I tried several different codes below, but the same error occurs.
sheet.buttons.whoseTitle.is('Go').first.elementClick(); sf.ui.proTools.windows.whoseTitle.is('Go').first.sheets.first.buttons.whoseTitle.is('Go').first.elementClick(); sf.ui.proTools.windows.whoseTitle.startsWith('Go').first.sheets.first.buttons.whoseTitle.is('Go').first.elementClick();
Apologies once again. And THANK YOU for all your help!
Christian Scheuer @chrscheuer2020-04-16 16:09:04.597Z
Can you show us a screen recording of this happening?
- DDaniel Lee @Daniel_Lee
Here's the link to the screen recording.
https://www.dropbox.com/s/0e6gm3t2n8quukv/SF Script Error 200417.mov?dl=0Thanks Christian.
Christian Scheuer @chrscheuer2020-04-16 20:41:59.535Z2020-04-16 21:13:45.292Z
Is there a 2nd screen where the window opens up that I'm not seeing here?
And are you running the exact code that I posted?- DDaniel Lee @Daniel_Lee
Hi Christian,
Yup, i'm using the exact code that you posted.
Nope, i dont think there's a window that opens. I've uploaded a video of both my screen when running the command. Heres the link to it.
https://www.dropbox.com/s/jsedptnyw7fdymy/IMG_7364.MOV?dl=0Thanks!
Christian Scheuer @chrscheuer2020-04-20 15:21:37.882Z
Hi Daniel.
I've added some more error handling in this version. It looks like your system might be reacting a little slowly to our inputting the folder name.
/** * @param {AxWindow} win * @param {string} path */ function navigateToInDialog(win, path) { const numberOfTriesClickingGo = 20; const timeToWaitBetweenGoAttempts = 100; //Open the Go to... sheet sf.keyboard.type({ text: '/' }); //Wait for the sheet to appear var sheet = win.sheets.first.elementWaitFor({ timeout: 500 }, 'Could not find "Go to" sheet in the Save/Open dialog').element; //Set the value of the combo box sheet.comboBoxes.first.value.value = path; //Press OK, try up to 10 times var goSuccess = false; for(var i=0; i<numberOfTriesClickingGo; i++) { if (sheet.buttons.whoseTitle.is('Go').first.elementClick({ onError: 'Continue' }).success) { goSuccess = true; break; } sf.wait({ intervalMs: timeToWaitBetweenGoAttempts }); } if (!goSuccess) throw "Could not click 'Go'"; //Wait for sheet to close win.sheets.first.elementWaitFor({ waitForNoElement: true, timeout: 500 }, '"Go to" sheet didn\'t close in time'); } function importSession(sessionPath) { sf.ui.proTools.appActivateMainWindow(); // Open up Import Session Data sf.ui.proTools.menuClick({ menuPath: ['File', 'Import', 'Session Data...'] }); // Wait for window to open var importWin = sf.ui.proTools.windows.whoseTitle.is('Open').first; // Navigate to folder navigateToInDialog(importWin, sessionPath); // Click Open importWin.buttons.whoseTitle.is('Open').first.elementClick(); // Wait for import window to close importWin.elementWaitFor({ waitForNoElement: true }); } function selectLastTack() { //Select last track in session var lastTrackName = sf.ui.proTools.trackNames.slice(-1)[0]; sf.ui.proTools.trackSelectByName({ names: [lastTrackName] }) sf.ui.proTools.selectedTrack.trackScrollToView(); } function setTimecode(value) { sf.ui.proTools.mainCounterSetValue({ targetValue: "Timecode", }); sf.ui.proTools.selectionSetTimecode({ mainCounter: value, }); } function askForAafFile(subFolderName) { //path of current session var folderPath = (sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/')) var originalFilesPath = folderPath + "/" + subFolderName; var aafFileCandidates = sf.file.directoryGetFiles({ path: originalFilesPath, isRecursive: true, searchPattern: '*.aaf' }).paths; var selectedPath = sf.interaction.popupSearch({ items: aafFileCandidates.map(p => ({ name: p.replace(originalFilesPath, '').substring(1), path: p, })), }).item.path; return selectedPath; } function main() { selectLastTack(); setTimecode("10:00:00:00"); var ptxPath = askForAafFile("Original Sessions & Files"); importSession(ptxPath); } main();
- DDaniel Lee @Daniel_Lee
Hi Christian,
Thanks for this! However, this only works 5 out of 10 times.
The error iskAXErrorInvalidUIElement (Test Script line 22)
This is the link to the video.
https://www.dropbox.com/s/7w2y2rslu9vpa11/SF Script Error 200421.mov?dl=0Christian Scheuer @chrscheuer2020-04-21 15:38:10.153Z
Yea, it seems like something on your computer is making file access a bit slow, so it fails because we're clicking Open before the dialog is ready.
Try this:
/** * @param {AxWindow} win * @param {string} path */ function navigateToInDialog(win, path) { const numberOfTriesClickingGo = 20; const timeToWaitBetweenGoAttempts = 100; //Open the Go to... sheet sf.keyboard.type({ text: '/' }); //Wait for the sheet to appear var sheet = win.sheets.first.elementWaitFor({ timeout: 500 }, 'Could not find "Go to" sheet in the Save/Open dialog').element; //Set the value of the combo box sheet.comboBoxes.first.value.value = path; //Press OK, try up to 10 times var goSuccess = false; for (var i = 0; i < numberOfTriesClickingGo; i++) { if (sheet.buttons.whoseTitle.is('Go').first.elementClick({ onError: 'Continue' }).success) { goSuccess = true; break; } sf.wait({ intervalMs: timeToWaitBetweenGoAttempts }); } if (!goSuccess) throw "Could not click 'Go'"; //Wait for sheet to close win.sheets.first.elementWaitFor({ waitForNoElement: true, timeout: 500 }, '"Go to" sheet didn\'t close in time'); } function importSession(sessionPath) { const numberOfTriesClickingOpen = 40; const timeToWaitBetweenOpenAttempts = 200; sf.ui.proTools.appActivateMainWindow(); // Open up Import Session Data sf.ui.proTools.menuClick({ menuPath: ['File', 'Import', 'Session Data...'] }); // Wait for window to open var importWin = sf.ui.proTools.windows.whoseTitle.is('Open').first; // Navigate to folder navigateToInDialog(importWin, sessionPath); // Click Open //Press Open, try up to 10 times var openSuccess = false; for (var i = 0; i < numberOfTriesClickingOpen; i++) { if (importWin.buttons.whoseTitle.is('Open').first.elementClick({ onError: 'Continue' }).success) { openSuccess = true; break; } sf.wait({ intervalMs: timeToWaitBetweenOpenAttempts }); } if (!openSuccess) throw "Could not click 'Open'"; // Wait for import window to close importWin.elementWaitFor({ waitForNoElement: true }); } function selectLastTack() { //Select last track in session var lastTrackName = sf.ui.proTools.trackNames.slice(-1)[0]; sf.ui.proTools.trackSelectByName({ names: [lastTrackName] }) sf.ui.proTools.selectedTrack.trackScrollToView(); } function setTimecode(value) { sf.ui.proTools.mainCounterSetValue({ targetValue: "Timecode", }); sf.ui.proTools.selectionSetTimecode({ mainCounter: value, }); } function askForAafFile(subFolderName) { //path of current session var folderPath = (sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/')) var originalFilesPath = folderPath + "/" + subFolderName; var aafFileCandidates = sf.file.directoryGetFiles({ path: originalFilesPath, isRecursive: true, searchPattern: '*.aaf' }).paths; var selectedPath = sf.interaction.popupSearch({ items: aafFileCandidates.map(p => ({ name: p.replace(originalFilesPath, '').substring(1), path: p, })), }).item.path; return selectedPath; } function main() { selectLastTack(); setTimecode("10:00:00:00"); var ptxPath = askForAafFile("Original Sessions & Files"); importSession(ptxPath); } main();
- DDaniel Lee @Daniel_Lee
Ah ok. Yup still getting the same error. Worked for me a couple of times previously, but cant get it to work at all now.
I compared the script, am I right to say that the difference is that you added more error handling in the importSession function?
Please pardon my ignorance but will the above help if the error I'm getting is in line 22 which is part of the navigateToInDialog function?
Christian Scheuer @chrscheuer2020-04-21 16:19:18.306Z
Oh no, you're right. Sorry I was busy building the next SF version so I was only testing this a little halfheartedly (since while I'm building I can't properly open up SF).
Can I get you to fill out this, right after having seen the error, so I can see a more full log?
Please click here to send us the information we need- DDaniel Lee @Daniel_Lee
No worries! Thanks for your help Chrisitan, I've filled out the the form after the error occured.
Christian Scheuer @chrscheuer2020-04-22 10:46:34.332Z
Thank you!
Christian Scheuer @chrscheuer2020-04-22 10:48:41.833Z
I added a little more error handling to this:
/** * @param {AxWindow} win * @param {string} path */ function navigateToInDialog(win, path) { const numberOfTriesClickingGo = 20; const timeToWaitBetweenGoAttempts = 100; //Open the Go to... sheet sf.keyboard.type({ text: '/' }); //Wait for the sheet to appear var sheet = win.sheets.first.elementWaitFor({ timeout: 500 }, 'Could not find "Go to" sheet in the Save/Open dialog').element; //Set the value of the combo box sheet.comboBoxes.first.value.value = path; //Press OK, try up to 10 times var goSuccess = false; for (var i = 0; i < numberOfTriesClickingGo; i++) { try { if (sheet.invalidate().buttons.whoseTitle.is('Go').first.elementClick({ onError: 'Continue' }).success) { goSuccess = true; break; } } catch (err) { } sf.wait({ intervalMs: timeToWaitBetweenGoAttempts }); } if (!goSuccess) throw "Could not click 'Go'"; //Wait for sheet to close win.sheets.first.elementWaitFor({ waitForNoElement: true, timeout: 500 }, '"Go to" sheet didn\'t close in time'); } function importSession(sessionPath) { const numberOfTriesClickingOpen = 40; const timeToWaitBetweenOpenAttempts = 200; sf.ui.proTools.appActivateMainWindow(); // Open up Import Session Data sf.ui.proTools.menuClick({ menuPath: ['File', 'Import', 'Session Data...'] }); // Wait for window to open var importWin = sf.ui.proTools.windows.whoseTitle.is('Open').first; // Navigate to folder navigateToInDialog(importWin, sessionPath); // Click Open //Press Open, try up to 10 times var openSuccess = false; for (var i = 0; i < numberOfTriesClickingOpen; i++) { try { if (importWin.invalidate().buttons.whoseTitle.is('Open').first.elementClick({ onError: 'Continue' }).success) { openSuccess = true; break; } } catch (err) { } sf.wait({ intervalMs: timeToWaitBetweenOpenAttempts }); } if (!openSuccess) throw "Could not click 'Open'"; // Wait for import window to close importWin.elementWaitFor({ waitForNoElement: true }); } function selectLastTack() { //Select last track in session var lastTrackName = sf.ui.proTools.trackNames.slice(-1)[0]; sf.ui.proTools.trackSelectByName({ names: [lastTrackName] }) sf.ui.proTools.selectedTrack.trackScrollToView(); } function setTimecode(value) { sf.ui.proTools.mainCounterSetValue({ targetValue: "Timecode", }); sf.ui.proTools.selectionSetTimecode({ mainCounter: value, }); } function askForAafFile(subFolderName) { //path of current session var folderPath = (sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/')) var originalFilesPath = folderPath + "/" + subFolderName; var aafFileCandidates = sf.file.directoryGetFiles({ path: originalFilesPath, isRecursive: true, searchPattern: '*.aaf' }).paths; var selectedPath = sf.interaction.popupSearch({ items: aafFileCandidates.map(p => ({ name: p.replace(originalFilesPath, '').substring(1), path: p, })), }).item.path; return selectedPath; } function main() { selectLastTack(); setTimecode("10:00:00:00"); var ptxPath = askForAafFile("Original Sessions & Files"); importSession(ptxPath); } main();
- DDaniel Lee @Daniel_Lee
Haha. I'm getting this error now.
Could not click 'Go' (Test Script line 32)
Tired it on a different system and got the same error.