Last Chance To Claim LIFETIME ACCESS. [~30 Seats left]

Apr 4, 2024

Disable Dragging Elements on Selection with pyRevit startup script

We all know that feeling when we've accidentally dragged a 3D element in Revit. It's not fun especially if we haven't even noticed it. So let's find a solution

How to stop dragging elements?

In Revit, there is a selection option menu that includes several toggles. One of these toggles is called "Drag Elements on Selection" among others.

We can turn it off, and problem sort of goes away.

However, many BIM Managers face an issue that, not every user deactivates this toggle. And it can lead to accidents by dragging elements, especially among less experienced Revit users. While most of the times it's not harmful, sometimes users might not even realize it and later you find an element floating in space because of that.

Solution

What if there was a way to automatically disable this setting by default, whenever users open the Revit Application? And this can actually be achieved by using startup script in pyRevit.

It's a script that will be executed every time Revit application is started and loads pyRevit. You can do a lot of things with it, but let's focus on this particular settings.

pyRevit start up script

To better understand startup script, I would recommend you to reference the pyRevit Dev Docs:

After reading the documentation you will learn that you just need to create startup.py file in the root folder of your extension (next to lib, and hooks folders if you have them already).

Script to Disable Drag Elements

Once you've created the file, we need to write a script that will change these settings, and it's super simple. We need to use SelectionUIOptions Class to disable these options.

And it's not complicated to use, here is a snippet you can paste in your startup.py script to get these options and change them.

# Imports

from pyrevit import HOST_APP, framework
from pyrevit import DB
from pyrevit import forms

# Variables
uidoc = HOST_APP.uidoc


# Get And Modify Options
from Autodesk.Revit.UI import SelectionUIOptions

opts = SelectionUIOptions.GetSelectionUIOptions()
opts.DragOnSelection  = False

#Other Options: (Select True/False)
#opts.SelectFaces	= False # / True
#opts.SelectLinks	= False # / True
#opts.SelectPinned	= False # / True
#opts.SelectUnderlay = False # / True
#opts.ActivateControlsAndDimensionsOnMultiSelect  = False #/ True

💡 There is no need for Transaction!

Join Newsletter

📩 You will be added to Revit API Newsletter

Join Us!

which is already read by 7200+ people!

Ready to become Revit Hero for your office? Learn Revit API!

Join this comprehensive course that will guide you step by step on how to create your dream tools for Revit that save time.