Revit View Underlay Python ScriptThe issue of Revit View Underlay setting has been bothering me for a really long time (well, not “really long time” but since I started using Revit for production), and in this post I will describe the issue and propose a solution with Revit Python Shell script. I have read around on various Revit forums and blogs and found a few other people complaining about this too, although I actually expected to see many more people bringing that up. So, the problem is when you batch – create a bunch of plan views for a series of level unless it is the “lowest” level in the document each of these views will come in with its View Underlay property set to have a level below as an underlay. Yes, that is the default behavior,  the question is who in the world would ever want to set an underlay for the majority of their plan views? Maybe every now and then, but it is mostly an exception rather than something that would deserve a default setting. I was hoping that I could actually change somewhere the default setting for the overlay setting, maybe Revit.ini file or some other place, but no – I couldn’t find it anywhere (if you know that it is possible PLEASE COMMENT!). It cannot even be controlled from View Template, so apparently it is set in stone. It really gets annoying when you just created 30-50 plan views and you have to go into each one of them and set View Underlay to None.

Luckily we have Revit Python shell and as at often happens one can fix a lot of things and stay much more effective / productive with just  a few lines of code. Below you will find a Python script that  will allow you to select a bunch of views from the Browser and set their View Underlay setting to None. Not a perfect solution (I wish we were allowed to control that from Revit.ini) but definitely better than clicking each view and changing it one by one. Remember – repetitive tasks destroy your brain cells – don’t settle for assembly-line tasks!

  1. Download the batchSetUnderlayToNone.txt script from here (assuming you have Revit Python Shell installed)
  2. Undock the Project Browser and select (Shift-Select) any views that you want to set Underlay to None (undocking the Project Browser will allow you to keep those view in the selection when you change to an active view to run Python Shell)
  3. Switch to any active view and fire up the Revit Python Shell (make sure the Selection Filter shows these earlier selected views in the active selection)
  4. Open the earlier downloaded batchSetUnderlayToNone.txt and run it…(that will set Underlay setting of all the selected views to None)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import clr
import math
clr.AddReference('RevitAPI') 
clr.AddReference('RevitAPIUI') 
from Autodesk.Revit.DB import * 
 
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
 
selection = uidoc.Selection
selEls = selection.Elements
t = Transaction(doc, 'Batch Set Underlay to None')
 
t.Start()
for el in selEls:
 
	if (el.Category.Id.IntegerValue == int(BuiltInCategory.OST_Views)) and (el.CanBePrinted):
		p = el.get_Parameter(BuiltInParameter.VIEW_UNDERLAY_ID)
		if (p is not None):
			p.Set(ElementId.InvalidElementId)
 
t.Commit()
Tagged with →  
Share →

2 Responses to Revit View Underlay Property and Python – Anoying Problem

  1. Dan Tartaglia says:

    Hi Dima,

    Looks good and very useful. My only comment is, why are you iterating through every element in the model? I normally code with the Revit API in C# but I’m sure you can access/use the: FilteredElementCollector() so that you only process plan views.

    // Set the iterator
    FilteredElementCollector collector = new FilteredElementCollector(doc);
    FilteredElementIterator itor = collector.OfClass(typeof(Autodesk.Revit.DB.ViewDrafting)).GetElementIterator();
    itor.Reset();

    // Itererate through each element
    while (itor.MoveNext())
    {
    Autodesk.Revit.DB.View oView = itor.Current as Autodesk.Revit.DB.ViewDrafting;

    }

    • Dima Chiriacov says:

      Hi Dan,
      Thanks for the input!
      Do you have the right file? In this particular solution I just iterate over the elements in the Selection object because user is suppose to pre-select views from the Project Browser:

      selection = uidoc.Selection
      selEls = selection.Elements
      for el in selEls:

      please see code snippet in the end of the blogpost

Leave a Reply

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>