SHIFT-Click: Config (or Alternative) Mode


SHIFT-Clicking on a button will run the config script. This config script is generally used to configure the main tool. Try Shift-Clicking on the Match tool in pyRevit → Modify panel and see the configuration window. Then try Shift clicking on the pyRevit Settings tool and see what it does.

<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/345c1731-b7a3-4de3-bdd9-2f18d451494d/ic_01_idea.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/345c1731-b7a3-4de3-bdd9-2f18d451494d/ic_01_idea.png" width="40px" /> When you are providing a config script in your bundle, or manage the SHIFT-Click inside your script, make sure the tooltip describes both behaviours and options. Follow the format below:

*"Tooltip text for main script"

Shift-Click: "Tooltip for config or alternative function"*

</aside>

IronPython and CPython Scripts

<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/676d2deb-55b5-4dfb-a3d5-4eb8e00f953a/alert.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/676d2deb-55b5-4dfb-a3d5-4eb8e00f953a/alert.png" width="40px" /> Note If you provide a secondary config script in your bundle, the main script will never get executed on SHIFT-Clicking your tool since the convention is to run the config script first. If you want to handle the ⇧ + Click inside your main code, make sure there is no config script inside your bundle.

</aside>

If you don’t define the configuration script, you can check the value of EXEC_PARAMS.config_mode in your scripts to change script behaviour. This is the method that the Settings command is using to open the config file location in explorer:

from pyrevit import EXEC_PARAMS

if EXEC_PARAMS.config_mode:
    do_task_A()
else:
    do_task_B()

# older scripts check the value of builtin __shiftclick__ directly
# but the above method is preferred
if __shiftclick__:
    do_task_A()
else:
    do_task_B()

.NET Scripts

SHIFT-Click on a button that contains .NET scripts, will run the config script if it exists.

You can also follow the example below, to check if the user has SHIFT-Clicked your tool, inside the main script.

See Anatomy of .NET (C#, VB) Scripts for more information on the structure of pyRevit .NET scripts.

// import pyRevit runtime namespace
using PyRevitLabs.PyRevit.Runtime;

namespace MyPyRevitDotNetCommands
{
   public class TestConfigMode : IExternalCommand
   {
      // add a public field with type PyRevitLabs.PyRevit.Runtime.ScriptData
      public ExecParams execParams;

      public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
      {
         // check the value of ConfigMode in you code
         if (execParams.ConfigMode)
             DoTaskA();
         else
             DoTaskB();

         return Result.Succeeded;
      }
   }
}
' import pyRevit runtime namespace
Imports PyRevitLabs.PyRevit.Runtime

Public Class TestDebugMode
    Implements IExternalCommand

    ' add a public field with type PyRevitLabs.PyRevit.Runtime.ScriptData
    Public execParams As ExecParams 
    
    Public Function Execute(ByVal revit As ExternalCommandData, _
                            ByRef message As String, _
                            ByVal elements As ElementSet) As Autodesk.Revit.UI.Result
                                Implements IExternalCommand.Execute
        ' check the value of ConfigMode in you code
        If execParams.ConfigMode Then
            DoTaskA()
        Else
            DoTaskB()
        End If

        Return Autodesk.Revit.UI.Result.Succeeded
    End Function
End Class

DynamoBIM and Grasshopper Scripts

SHIFT-Click on a button that contains DynamoBIM, or Grasshopper scripts, will run the config script if it exists. This will provide a method to include a second scripts inside the same bundle as alternative function of the tool.

<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/5f8251e6-d7ee-4e51-815f-e635004a5d9e/alert.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/5f8251e6-d7ee-4e51-815f-e635004a5d9e/alert.png" width="40px" /> Currently there is no mechanism for checking the value of Config Mode in DynamoBIM or Grasshopper scripts.

</aside>

CTRL-Click: Debug Mode