No internet connection
  1. Home
  2. How to

Templating String Array

By Owen Granich-Young @Owen_Granich_Young
    2021-11-03 20:01:32.930Z

    @Kitch Great chatting with you today in the webinar. Tried to do a template of the array, I'm sure I got someting wrong. I should have looked closer how you wrote the constant (I saw it was recorded where do I find that as to not bother you with dumb questions after again next time?)

    Orignal Forum post where I found this Move clip to specified track - if partial or full overwrite move to next track

    AAF organization :

    function cutButRememberSelection() {
    
        sf.ui.proTools.mainCounterDoWithValue({
            targetValue: 'Samples',
            action: () => {
                //Get original selection
                var originalSelection = sf.ui.proTools.selectionGetInSamples();
    
                var editCut = sf.ui.proTools.getMenuItem('Edit', 'Cut');
                if (!editCut.isEnabled) throw 'No clip selected';
                editCut.elementClick({}, 'Could not cut clip');
    
                sf.ui.proTools.selectionSetInSamples({
                    selectionStart: originalSelection.selectionStart,
                    selectionEnd: originalSelection.selectionEnd,
                });
            }
        });
    
    }
    
    function selectionOverlapsWithExistingClip() {
        return sf.ui.proTools.getMenuItem("Edit", "Trim Clip", "To Selection").exists;
    }
    
    function moveToTracks(trackNames) {
        var originalTrackName = sf.ui.proTools.selectedTrackNames[0];
    
        cutButRememberSelection();
    
        var success = false;
        for (var i = 0; i < trackNames.length; i++) {
            var trackName = trackNames[i];
    
            sf.ui.proTools.trackSelectByName({
                names: [trackName],
                deselectOthers: true,
            });
    
            //Update menu
            sf.keyboard.press({ keys: 'cmd+shift+numpad plus,cmd+shift+numpad minus' });
            if (selectionOverlapsWithExistingClip())
                continue;
    
            var editPaste = sf.ui.proTools.getMenuItem('Edit', 'Paste');
            if (!editPaste.isEnabled) throw 'Cannot paste here';
            editPaste.elementClick({}, 'Could not paste clip');
            success = true;
            break;
        }
    
        sf.ui.proTools.trackSelectByName({
            names: [originalTrackName],
            deselectOthers: true,
        });
    
        if (!success) {
            sf.ui.proTools.getMenuItem('Edit', 'Undo Cut').elementClick();
        }
    }
    
    moveToTracks([
        'DX_1',
        'DX_2',
        'DX_3',
        'DX_4',
        'DX_5',
        'DX_6',
        
    ]);
    
    

    Attempt at making a template with the array (pretty sure it's my constant that's totally wrong? but not sure where to look to fix it...

    const trackNames = event.props.trackNames;
    sf.ui.proTools.appActivateMainWindow();
    sf.ui.proTools.invalidate();
    
    function cutButRememberSelection() {
    
        sf.ui.proTools.mainCounterDoWithValue({
            targetValue: 'Samples',
            action: () => {
                //Get original selection
                var originalSelection = sf.ui.proTools.selectionGetInSamples();
    
                var editCut = sf.ui.proTools.getMenuItem('Edit', 'Cut');
                if (!editCut.isEnabled) throw 'No clip selected';
                editCut.elementClick({}, 'Could not cut clip');
    
                sf.ui.proTools.selectionSetInSamples({
                    selectionStart: originalSelection.selectionStart,
                    selectionEnd: originalSelection.selectionEnd,
                });
            }
        });
    
    }
    
    function selectionOverlapsWithExistingClip() {
        return sf.ui.proTools.getMenuItem("Edit", "Trim Clip", "To Selection").exists;
    }
    
    function moveToTracks(trackNames) {
        var originalTrackName = sf.ui.proTools.selectedTrackNames[0];
    
        cutButRememberSelection();
    
        var success = false;
        for (var i = 0; i < trackNames.length; i++) {
            var trackName = trackNames[i];
    
            sf.ui.proTools.trackSelectByName({
                names: [trackName],
                deselectOthers: true,
            });
    
            //Update menu
            sf.keyboard.press({ keys: 'cmd+shift+numpad plus,cmd+shift+numpad minus' });
            if (selectionOverlapsWithExistingClip())
                continue;
    
            var editPaste = sf.ui.proTools.getMenuItem('Edit', 'Paste');
            if (!editPaste.isEnabled) throw 'Cannot paste here';
            editPaste.elementClick({}, 'Could not paste clip');
            success = true;
            break;
        }
    
        sf.ui.proTools.trackSelectByName({
            names: [originalTrackName],
            deselectOthers: true,
        });
    
        if (!success) {
            sf.ui.proTools.getMenuItem('Edit', 'Undo Cut').elementClick();
        }
    }
    
    moveToTracks([
        trackNames,
        
    ]);
    
    

    Error at Line 39

    03.11.2021 12:36:14.85 <info> [Backend]: !! Command Error: DX [user:ckue9hwvi0000y210la4y5yq9:ckvjwy86i0004v110x5bwguvv#ckvjx23h50006v110r1on9b78]:
        Error: Expected string but got Object
    (AAF ORG TEMPLATE line 39) 
    

    I'm sure this is a 'duh' situation...

    Bests,
    Owen

    Solved in post #2, click to view
    • 13 replies
    1. Kitch Membery @Kitch2021-11-03 20:10:40.380Z

      Hi @Owen_Granich_Young,

      Great chatting with you also, legend!

      You were so close. This may be a quick fix, though I have not tested though.

      If you change

      moveToTracks([
          trackNames,
          
      ]);
      

      to

      moveToTracks(trackNames);
      

      That may do the trick :-)

      Let me know if it works for you?
      Rock on

      FYI The recording of the webinars is for internal use only. :-)

      ReplySolution
      1. Kitch Membery @Kitch2021-11-03 20:15:20.473Z

        @Owen_Granich_Young,

        The reason for that change is;

        trackNames is already a string array string[] eg ["Guitar","Vocal","Piano"]

        by having trackNames surrounded by square brackets [trackNames], puts the trackNames array inside another array ie [["Guitar","Vocal","Piano"]]

        I hope that makes sense :-)

        1. Hmm, It did not like that.. thought maybe it was a stream deck thing tried with a key command, no dice.

          03.11.2021 13:20:58.65 <info> [Backend]: Error parsing command AAF ORG TEMPLATE (Line 69): Unexpected token ]
          Logging error in action (01) RunCommandAction: Command 'user:ckue9hwvi0000y210la4y5yq9:ckvjwy86i0004v110x5bwguvv' not found
          !! Command Error: DX_1 [user:ckue9hwvi0000y210la4y5yq9:ckvjwy86i0004v110x5bwguvv#ckvjypszw0009v11029rkzjc7]:
             Command 'user:ckue9hwvi0000y210la4y5yq9:ckvjwy86i0004v110x5bwguvv' not found
          
          << Command: DX_1 [user:ckue9hwvi0000y210la4y5yq9:ckvjwy86i0004v110x5bwguvv#ckvjypszw0009v11029rkzjc7]
          
          

          Thoughts?

          1. I wonder if I broke it by accidently creating a new String array with the same trackNames as was previously in the script? .... Trying something

            1. Nope, same error.

              Latest Atempted code

              const yourTracksGoHere = event.props.yourTracksGoHere;
              sf.ui.proTools.appActivateMainWindow();
              sf.ui.proTools.invalidate();
              function cutButRememberSelection() {
              
                  sf.ui.proTools.mainCounterDoWithValue({
                      targetValue: 'Samples',
                      action: () => {
                          //Get original selection
                          var originalSelection = sf.ui.proTools.selectionGetInSamples();
              
                          var editCut = sf.ui.proTools.getMenuItem('Edit', 'Cut');
                          if (!editCut.isEnabled) throw 'No clip selected';
                          editCut.elementClick({}, 'Could not cut clip');
              
                          sf.ui.proTools.selectionSetInSamples({
                              selectionStart: originalSelection.selectionStart,
                              selectionEnd: originalSelection.selectionEnd,
                          });
                      }
                  });
              
              }
              
              function selectionOverlapsWithExistingClip() {
                  return sf.ui.proTools.getMenuItem("Edit", "Trim Clip", "To Selection").exists;
              }
              
              function moveToTracks(trackNames) {
                  var originalTrackName = sf.ui.proTools.selectedTrackNames[0];
              
                  cutButRememberSelection();
              
                  var success = false;
                  for (var i = 0; i < trackNames.length; i++) {
                      var trackName = trackNames[i];
              
                      sf.ui.proTools.trackSelectByName({
                          names: [trackName],
                          deselectOthers: true,
                      });
              
                      //Update menu
                      sf.keyboard.press({ keys: 'cmd+shift+numpad plus,cmd+shift+numpad minus' });
                      if (selectionOverlapsWithExistingClip())
                          continue;
              
                      var editPaste = sf.ui.proTools.getMenuItem('Edit', 'Paste');
                      if (!editPaste.isEnabled) throw 'Cannot paste here';
                      editPaste.elementClick({}, 'Could not paste clip');
                      success = true;
                      break;
                  }
              
                  sf.ui.proTools.trackSelectByName({
                      names: [originalTrackName],
                      deselectOthers: true,
                  });
              
                  if (!success) {
                      sf.ui.proTools.getMenuItem('Edit', 'Undo Cut').elementClick();
                  }
              }
              
              moveToTracks(yourTracksGoHere);
                  
              ]);
              
              

              Latest Error

              03.11.2021 13:33:44.33 <info> [Backend]: Error parsing command AAF Org Template (Line 67): Unexpected token ]
              Logging error in action (01) RunCommandAction: Command 'user:ckue9hwvi0000y210la4y5yq9:ckvjz1ywy000bv1109tkjpi1g' not found
              !! Command Error: Yourtracks_DX [user:ckue9hwvi0000y210la4y5yq9:ckvjz1ywy000bv1109tkjpi1g#ckvjz5847000dv110x8qbxedq]:
                  Command 'user:ckue9hwvi0000y210la4y5yq9:ckvjz1ywy000bv1109tkjpi1g' not found
              
              << Command: Yourtracks_DX [user:ckue9hwvi0000y210la4y5yq9:ckvjz1ywy000bv1109tkjpi1g#ckvjz5847000dv110x8qbxedq]
              
              
              1. Kitch Membery @Kitch2021-11-03 20:39:04.208Z

                Ahhh... Make sure you delete ]); at the end of the script and try again.

                1. Huzzah! I knew it had to be someting dumb on my part! Thanks boss!

                  Now to blowout all these pesky repetitive scripts and make them all in the template and update the package.

                  1. Kitch Membery @Kitch2021-11-03 20:46:07.807Z

                    Awesome!! :-)

                2. Kitch Membery @Kitch2021-11-03 20:44:11.848Z

                  Note: To follow best practices, I think the name you were using for the Template property was better before ie trackNames.

                  1. Haha, ok I'll swap it back up and double check it still works!

                  2. Kitch Membery @Kitch2021-11-03 20:45:47.205Z

                    Then use the Description field like this.

                    1. Done and done. In the store as AAF ORGANIZER package if anybody happend to be following along here and would find it useful.

                      1. Kitch Membery @Kitch2021-11-03 21:54:52.368Z

                        Noice!!! :-)