No internet connection
  1. Home
  2. Support

Create Instrument Plugin

By Caleb Nelson @Caleb_Nelson
    2020-10-25 05:07:34.339Z2020-10-25 18:22:22.168Z

    Trying to write a script that creates a stereo instrument track and places a specified instrument plugin on the insert. I have something that works about 50% of the time. Wondering if someone can spot any errors in my code? Thank you in advance.

    sf.ui.proTools.menuClick({
        menuPath: ["Track","New..."],
    });
    
    sf.wait({
        intervalMs: 500,
    });
    
    sf.ui.proTools.windows.whoseTitle.is('New Tracks').first.popupButtons.whoseTitle.is('Audio Track').first.popupMenuSelect({
        menuPath: ["Instrument Track"],
    });
    
    sf.ui.proTools.windows.whoseTitle.is('New Tracks').first.popupButtons.whoseTitle.is('Mono').first.popupMenuSelect({
        menuPath: ["Stereo"],
    });
    
    sf.ui.proTools.windows.whoseTitle.is('New Tracks').first.buttons.whoseTitle.is('Create').first.elementClick();
    sf.wait({
        intervalMs: 1000,
    });
    
    function getFirstFreeInsertIndex() {
        var btns = sf.ui.proTools.selectedTrack.invalidate().insertButtons;
        for (var i = 0; i < 10; i++)
            if (btns[i].value.invalidate().value === "unassigned") return i;
        return -1;
    }
    
    sf.ui.proTools.selectedTrack.trackInsertOrSendSelect({
        insertOrSend: 'Insert',
        pluginNumber: getFirstFreeInsertIndex() + 1,    
        pluginPath: ['multichannel plug-in', 'Instrument', 'Keyscape (stereo)']
    });
    

    Here's the error I'm getting:

    24.10.2020 22:03:44.13 <info> [Backend]: JavaScript error with InnerException: System.Exception: Parent's UIElement was null: SoundFlow.Shortcuts.AXUIElementException: kAXErrorInvalidUIElement
       at SoundFlow.Shortcuts.AXUIElement.GetSubElements(String) + 0x1a5
       at SoundFlow.Shortcuts.Ax.AxNodes.AxPtTrackInsertSendButton.GetUIElement() + 0xe7
       at SoundFlow.Shortcuts.Ax.AxNodes.AxElement.LoadUIElement() + 0x27 (AxPtTrackInsertSendButton)
       at SoundFlow.Shortcuts.Ax.AxNodes.AxNode.RequireParentUI() + 0x82
       at SoundFlow.Shortcuts.Ax.AxNodes.AxStringOrIntProperty.<get_Value>b__6_0() + 0x13
       at SoundFlow.Shortcuts.Ax.AxNodes.AxNode.GetOrCreateValue[TValue](TValue&, Func`1) + 0x24
       at sfbackend!<BaseAddress>+0x2311e8f
       at sfbackend!<BaseAddress>+0x12360ae
    !! Command Error: KEYSCAPE [user:ckgo4siic0007xz10ry1yq1ym:ckgome3z8000acq103gvmfm0g]:
    Error: Parent's UIElement was null: SoundFlow.Shortcuts.AXUIElementException: kAXErrorInvalidUIElement
       at SoundFlow.Shortcuts.AXUIElement.GetSubElements(String) + 0x1a5
       at SoundFlow.Shortcuts.Ax.AxNodes.AxPtTrackInsertSendButton.GetUIElement() + 0xe7
       at SoundFlow.Shortcuts.Ax.AxNodes.AxElement.LoadUIElement() + 0x27 (AxPtTrackInsertSendButton)
    (KEYSCAPE line 25) 
    
    << Command: KEYSCAPE [user:ckgo4siic0007xz10ry1yq1ym:ckgome3z8000acq103gvmfm0g]
    
    24.10.2020 22:03:44.52 <info> [StartMenu]: Uncaught TypeError: sender.emit is not iterable (cannot read property Symbol(Symbol.iterator)) Line 2188 electron/js2c/renderer_init.js
    24.10.2020 22:03:44.52 <info> [StartMenu]: Uncaught TypeError: sender.emit is not iterable (cannot read property Symbol(Symbol.iterator)) Line 2188 electron/js2c/renderer_init.js
    
    • 3 replies
    1. Do you have all Inserts A-E and F-J shown? This could be the source of the issue.

      On another note - please check this tutorial for how to quote code in the SoundFlow forum, so that it displays in a readable format (I've edited your post now):

      1. Your code also seems to be using manual wait times instead of waiting on UI elements.

        I'd highly recommend using "Wait for UI Element" actions instead of manual waits. Switching to UI Element waits will greatly enhance the stability of your code. You can learn more about this technique in these 2 tutorials:

      2. C
        In reply toCaleb_Nelson:
        Caleb Nelson @Caleb_Nelson
          2020-10-25 18:57:42.792Z

          Thank you Christian. The "Wait for UI Element" made this way more stable, as you predicted. For anyone interested, here's a script to quickly bring up an instrument track with a prescribed instrument, in this case keyscape:

          sf.ui.proTools.menuClick({
              menuPath: ["Track","New..."],
          });
          
          sf.ui.proTools.windows.whoseTitle.is('New Tracks').first.elementWaitFor({
              waitType: "Appear",
          });
          
          sf.ui.proTools.windows.whoseTitle.is('New Tracks').first.popupButtons.whoseTitle.is('Audio Track').first.popupMenuSelect({
              menuPath: ["Instrument Track"],
          });
          
          sf.ui.proTools.windows.whoseTitle.is('New Tracks').first.popupButtons.whoseTitle.is('Mono').first.popupMenuSelect({
              menuPath: ["Stereo"],
          });
          
          sf.ui.proTools.windows.whoseTitle.is('New Tracks').first.buttons.whoseTitle.is('Create').first.elementClick();
          
          sf.ui.proTools.windows.whoseTitle.is('New Tracks').first.elementWaitFor({
              waitType: "Disappear",
          });
          
          function getFirstFreeInsertIndex() {
              var btns = sf.ui.proTools.selectedTrack.invalidate().insertButtons;
              for (var i = 0; i < 10; i++)
                  if (btns[i].value.invalidate().value === "unassigned") return i;
              return -1;
          }
          
          sf.ui.proTools.selectedTrack.trackInsertOrSendSelect({
              insertOrSend: 'Insert',
              pluginNumber: getFirstFreeInsertIndex() + 1,    
              pluginPath: ['multichannel plug-in', 'Instrument', 'Keyscape (stereo)']
          });