No internet connection
  1. Home
  2. How to

Is there a way to search by region name and color all named "X" a specified color?

By Jon Lipman @Jon_Lipman
    2022-02-20 06:29:24.085Z

    The idea would be for spotting BGs...say I have all locations marked as region groups named "This Location" or "That Location"
    Is there a script I could use to change all regions named "This Location" red and all "That Location" blue for example?

    Almost like a batch rename but with colors

    Solved in post #2, click to view
    • 22 replies

    There are 22 replies. Estimated reading time: 16 minutes

    1. samuel henriques @samuel_henriques
        2022-02-22 17:51:46.562Z2022-02-23 10:49:27.863Z

        Hello Jon,

        This should do it.
        Set your name-color list on the top of the script.
        Add as many as you want. Clip names that are not in the list will be ignored.

        Make a selection of clips and it will do it for all selected, on all selected tracks.

        Hope this is it.

        const colorName = {
            "This Location": { colorBrightness: "Light", colorNumber: 8 },
            "That Location": { colorBrightness: "Light", colorNumber: 13 },
        };
        
        
        function getClipName() {
            sf.ui.proTools.menuClick({ menuPath: ["Clip", "Rename..."] });
            const renameWin = sf.ui.proTools.windows.whoseTitle.is("Name").first.elementWaitFor({}, 'Rename Clip Window Not Found.').element;
            const clipName = renameWin.groups.first.textFields.first.value.invalidate().value;
            renameWin.buttons.whoseTitle.is("Cancel").first.elementClick();
            renameWin.elementWaitFor({ waitType: "Disappear" }, 'Rename Clip Window Failed to Close.');
            return clipName;
        };
        
        
        /**
        * @param {string} name
        */
        function setClipColor(name) {
            if (name in colorName) {
                sf.ui.proTools.colorsSelect({
                    colorTarget: "ClipsInTracks",
                    colorBrightness: colorName[name].colorBrightness,
                    colorNumber: colorName[name].colorNumber
                });
            };
        };
        
        
        sf.ui.proTools.appActivateMainWindow();
        sf.ui.proTools.invalidate();
        
        //Get selected tracks
        const originalTracks = sf.ui.proTools.selectedTrackNames;
        
        //Do for each track.
        sf.ui.proTools.selectedTracks.trackHeaders.slice().map(track => {
        
            //Select track
            track.trackSelect();
        
            //Scroll track into View
            track.trackScrollToView();
        
            // Color each selected clip
            sf.ui.proTools.clipDoForEachSelectedClip({
                action: () => {
        
                    setClipColor(getClipName())
        
                },
                onError: "Continue"
            })
        });
        
        //Restore previously selected tracks
        sf.ui.proTools.trackSelectByName({ names: originalTracks });
        
        Reply1 LikeSolution
        1. JJon Lipman @Jon_Lipman
            2022-02-22 20:30:30.384Z

            Thanks Samuel - I pased the script and replaced your "This Location" and "That Location" with corresponding "1" and "4" as a test and not really sure what happened but here's a video of the screen below...it jumped around onto other tracks and started renaming and trimming.

            Any ideas?

            https://we.tl/t-Sd9arGkfYv

            1. samuel henriques @samuel_henriques
                2022-02-22 20:57:25.320Z

                Hey Jon,

                Thank you for the video it makes it easier to spot what could me wrong.
                Didn't see any trimming, not sure about that.
                It is actually working as intended, It works on selected tracks and in the video it processed clips on the selected tracks.
                Since you have "Link Track and Edit Selection" disabled,
                when you made the initial selection it didn't change the selected tracks.

            2. J
              In reply toJon_Lipman:
              Jon Lipman @Jon_Lipman
                2022-02-22 21:45:04.427Z

                Hmmm still not working for me even with all both timeline and track link turned off.

                In this video I have only the track selected that contains the regions I want re-colored.

                I do 3 things in this video:

                1. Run the script with the track selected but not the regions
                2. Run the script with the tracks selected AND the regions
                3. This is an example of me manually doing what I'm attempting to achieve with this script (just in case I wasn't clear in my description)

                https://we.tl/t-NiP3Kt3vxb

                1. samuel henriques @samuel_henriques
                    2022-02-22 22:44:29.129Z

                    Sorry Jon, just found a way it could behave as in the video.
                    Could you check that the groups and audio are shown in the clip list?

                    Clip list doesn't have to be opened but Audio end Groups must be shown, otherwise pro tools wont open the clip name window, witch we need to know the name of the selected clip.

                    If it's common you keep these hidden, I can white something to make sure they are shown.

                  • J
                    In reply toJon_Lipman:
                    Jon Lipman @Jon_Lipman
                      2022-02-23 07:10:05.121Z

                      Hi Samuel...yes I can confirm that both audio and groups were shown in the clip list...just to be safe I went ahead and checked color, timebase, processing state and file type to match your example but still no luck.

                      Could this be some minor error on my end that's screwing this up?

                      I copy pasted your script exactly and only changed the names of the regions to be affected.

                      1. J
                        In reply toJon_Lipman:
                        Jon Lipman @Jon_Lipman
                          2022-02-23 07:15:25.954Z

                          Ok so this is interesting...just to experiment, I created a brand new project with a single track and tried the script out and as long as I had the regions selected, success!

                          The original session I was trying this in is a very large session containing about 50gb of audio files and a massive clip bin...is it possible the sheer size of the session is preventing this from working somehow?

                          1. JJon Lipman @Jon_Lipman
                              2022-02-23 07:19:14.437Z

                              Also (although maybe this is how you designed it) it only works across a single track...so even if I selected regions on multiple tracks with all selected, it only applied the color changes to the first track then gave me this error.

                              22.02.2022 23:18:09.76 [Backend]: Logging error in action (01) TrackScrollToViewAction: Selected track header and track list item does not match. List Name: ''. Header Name: '2'

                              22.02.2022 23:18:09.76 [Backend]: !! Command Error: Color [user:ckz4kpwnr0005t2101rnyu5v1:ckzykoy260000qj105plz6zei]:
                              Selected track header and track list item does not match. List Name: ''. Header Name: '2' (Color: Line 41)

                              1. samuel henriques @samuel_henriques
                                  2022-02-23 09:21:43.870Z

                                  Will try to figure it. You must make a selection and it will process the clips within the selection. So your test with a selection is the correct one.

                                  1. samuel henriques @samuel_henriques
                                      2022-02-23 10:49:09.545Z

                                      AHHH!!! Got it, found two stupid mistakes on the script.
                                      Just updated above, hope this is it.

                                      Just to clarify, it will check the name of the clip and color it depending on your list,
                                      all selected clips only on all selected tracks.

                                      Hope this was the problem, my apologies.

                                      1. JJon Lipman @Jon_Lipman
                                          2022-02-23 18:04:09.813Z

                                          Hey Samuel...did you update the first script that you posted? I copy pasted that in but I'm having the same results...I'm uploading another video just to be sure you can see what's going on...thanks for your help with this!

                                          https://we.tl/t-yVRDY3cde0

                                          1. samuel henriques @samuel_henriques
                                              2022-02-23 18:11:24.421Z

                                              I did update, checked your video thank you. What version of pro tools are you on?

                                              Could you try to quit and restart soundFlow please?

                                              1. samuel henriques @samuel_henriques
                                                  2022-02-23 18:31:40.699Z

                                                  if it doesn't work could you check this test script please.
                                                  Select a few tracks and run script.
                                                  The script will select each track and log its name.

                                                  
                                                  sf.ui.proTools.appActivateMainWindow();
                                                  sf.ui.proTools.invalidate();
                                                  
                                                  //Get selected tracks
                                                  const originalTracks = sf.ui.proTools.selectedTrackNames;
                                                  
                                                  //Do for each track.
                                                  sf.ui.proTools.selectedTracks.trackHeaders.slice().map(track => {
                                                  
                                                      //Select track
                                                      track.trackSelect();
                                                  
                                                      //Scroll track into View
                                                      track.trackScrollToView();
                                                  
                                                      log(sf.ui.proTools.selectedTrackNames[0])
                                                  });
                                                  
                                                  
                                                  
                                                  1. JJon Lipman @Jon_Lipman
                                                      2022-02-23 18:36:30.575Z

                                                      Success! I restarted soundflow after updating the script and it's working now...thank you!

                                                      BTW - I'm on PT 2021.12.0

                                                      1. samuel henriques @samuel_henriques
                                                          2022-02-23 18:38:55.499Z

                                                          Awesome, it looks like soundFlow didn't update the script when you made the new paste.

                                                          Keep testing it and let me know how it goes.

                                                          1. samuel henriques @samuel_henriques
                                                              2022-02-23 18:40:06.022Z

                                                              Also I made a version that will set the view on the clip list in case they are not enabled. Let me know if you'd like it.

                                                              1. JJon Lipman @Jon_Lipman
                                                                  2022-02-24 17:56:16.307Z

                                                                  Awesome thanks...I pretty much always have those on in the clip list so it's probably just another step I don't need - so far so good...

                                                                  So the reason I'm requesting this script is to spot BGs - I'll break a show up into named clips spanning recurring locations. So I'll maybe color all "Jon's House" region groups red. Then I go back and take my 5 minute long "Jon's House" clip group containing all the BG audio for that location and put it under everything red - trim to fit, ungroup and add fades.

                                                                  1. Trip Brock @Trip_Brock
                                                                      2022-07-06 06:54:56.105Z

                                                                      Hi Samuel, I came across this thread with the script that you wrote which is very cool and helpul as i'm trying to learn more about this great software! How would I go about modifiying this script slightly so that the clip coloring that the script provides happens on the selected clip names that (start with) or (contain) the text names in the name-color list, as opposed to having to be an exact match? Is this possible? Many thanks!

                                                                      1. samuel henriques @samuel_henriques
                                                                          2022-07-06 12:43:50.596Z2022-07-06 18:33:54.274Z

                                                                          Hello Trip,
                                                                          Try this:

                                                                          const colorName = {
                                                                              "Int": { colorBrightness: "Light", colorNumber: 8 },
                                                                              "Ext": { colorBrightness: "Light", colorNumber: 13 },
                                                                              "Kitchen": { colorBrightness: "Light", colorNumber: 20 },
                                                                          };
                                                                          
                                                                          
                                                                          function getClipName() {
                                                                              sf.ui.proTools.menuClick({ menuPath: ["Clip", "Rename..."] });
                                                                              const renameWin = sf.ui.proTools.windows.whoseTitle.is("Name").first.elementWaitFor({}, 'Rename Clip Window Not Found.').element;
                                                                              const clipName = renameWin.groups.first.textFields.first.value.invalidate().value;
                                                                              renameWin.buttons.whoseTitle.is("Cancel").first.elementClick();
                                                                              renameWin.elementWaitFor({ waitType: "Disappear" }, 'Rename Clip Window Failed to Close.');
                                                                              return clipName;
                                                                          };
                                                                          
                                                                          
                                                                          /**
                                                                          * @param {string} name
                                                                          */
                                                                          function setClipColor(name) {
                                                                          
                                                                              const nameInColorName = Object.keys(colorName).filter(color => color.toLowerCase().indexOf(name.split(" ")[0].toLowerCase()) > -1)[0];
                                                                          
                                                                              if (nameInColorName) {
                                                                                  sf.ui.proTools.colorsSelect({
                                                                                      colorTarget: "ClipsInTracks",
                                                                                      colorBrightness: colorName[nameInColorName].colorBrightness,
                                                                                      colorNumber: colorName[nameInColorName].colorNumber
                                                                                  });
                                                                              };
                                                                          
                                                                          };
                                                                          
                                                                          
                                                                          function main() {
                                                                              sf.ui.proTools.appActivateMainWindow();
                                                                              sf.ui.proTools.invalidate();
                                                                          
                                                                              //Get selected tracks
                                                                              const originalTracks = sf.ui.proTools.selectedTrackNames;
                                                                          
                                                                              //Do for each track.
                                                                              sf.ui.proTools.selectedTracks.trackHeaders.slice().map(track => {
                                                                          
                                                                                  //Select track
                                                                                  track.trackSelect();
                                                                          
                                                                                  //Scroll track into View
                                                                                  track.trackScrollToView();
                                                                          
                                                                                  // Color each selected clip
                                                                                  sf.ui.proTools.clipDoForEachSelectedClip({
                                                                                      action: () => {
                                                                                          setClipColor(getClipName())
                                                                                      },
                                                                                      onError: "Continue"
                                                                                  })
                                                                              });
                                                                          
                                                                              //Restore previously selected tracks
                                                                              sf.ui.proTools.trackSelectByName({ names: originalTracks });
                                                                          };
                                                                          
                                                                          main();
                                                                          
                                                                          1. Trip Brock @Trip_Brock
                                                                              2022-07-06 17:33:42.816Z

                                                                              Hi Samuel, thanks for looking into this so quickly! It still seems to only change the color of the clips when the clip name is an exact match to what is in the name-color list. I'm trying to use this with scene markers to color code all Interior scenes one color and all Exterior scenes a different color. Scene clip name examples would be "Int House Night", "Int Kitchen Day", "Int Diner" - where I want to color all clips that contain "Int" the same color. Many thanks!

                                                                              1. samuel henriques @samuel_henriques
                                                                                  2022-07-06 18:46:02.292Z2022-07-06 19:44:53.272Z

                                                                                  -- UPDATED ABOVE --
                                                                                  You are correct, on my test it was working, but I was wrong.
                                                                                  I'm avoiding startsWith because I'm guessing you'll want to tweak this to be more useful with more locations, so with a little tweak its easy to change.
                                                                                  As it is working now, it will split the name at the " " (space) so "Int House Night" will become an array ["Int", "House", "Night"] and is taking the first in the array [0] and looking in your color list.
                                                                                  in this line:

                                                                                  const nameInColorName = Object.keys(colorName).filter(color => color.toLowerCase().indexOf(name.split(" ")[0].toLowerCase()) > -1)[0];
                                                                                  

                                                                                  if you change the first ( not the last one) [0] to [1] it will look for the second word of the name, in this example "House".

                                                                                  Let me know if this makes sense, and if it's working for you.

                                                                                  1. Trip Brock @Trip_Brock
                                                                                      2022-07-06 19:41:18.632Z

                                                                                      Wow thank you for the quick response- and yes this is now working greast. Thank you for the explanation
                                                                                      as well, this is super helpful! Cheers!