Happy past Labor Day everyone! However, I’d like too celebrate “less-labor – more-coding” attitude to things I thought I would share this post on “Title on Sheet” View property batch update, and will give another opportunity for Revit API and Revit Python Shell to shine.
A colleague of mine brought up the issue of Revit ‘s View Name vs Title on Sheet view properties for a project. View Name was used to organize views in the browser and as a subscript every View Name had a number of a drawing series that each view belongs to. For example 0200 Level 10 Pooldeck (0200 for Life Safety series) or 0300 Level 10 Pooldeck (0200 for Overall floor-plans) – you get the idea. So all the views were named and created and my colleague wanted for the Title on Sheet property to display just the Level name without the series (i.e. 0200 Level 1 to just Level 1) without having to go one by one and fill up every view’s Title on Sheet property. Oh, and since view names change every now and then (depending on the project direction), he wanted to have an ability to batch update Title on Sheet properties whenever he wants. As you know both View Name and Title on Sheet properties are not connected in any way and there is no “out-of-the-box” way to make this sort of batch update in Revit.
Here is when Revit Python Shell and Revit API come into play. The problem described earlier can be solved quickly with a short Python script that can be stored to be reused later. All this script needs to do is:
- to collect all the views in the project (all views for simplicity – in reality you probably want to have your script filter out working views and other ones the naming of which will follow different logic) and iterate over every one of them
- grab view’s View Name information
- format the string to remove first 5 characters
- assign that string to view’s Title on Sheet property
1 2 3 4 5 6 7 8 9
#what is the view type that you are querying myViewType = ViewType.FloorPlan filterPar1 = 'Production/Working' filterPar1Val = 'Production' for el in elSet1: if(not el.IsTemplate and el.CanBePrinted and el.ViewType == myViewType): #custom view property filter if(el.get_Parameter(filterPar1).AsString() == filterPar1Val):
This particular snippet from the Python script filters out views by being a “FloorPlan” and by one of my custom view parameters “Production/Working” with value of “Production”. Obviously you need to modify these properties to match what you are looking to accomplish – if you want to filter out views you need to replace my parameters with yours.
The download button and the full script is below. Enjoy!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#dp Stuff | http://dp-stuff.org | updateViewTitleOnSheetName #this Revit Python Script copies View Name property information of each view #removes specified amount of characters from the front #and assigns it to Title on Sheet view property import clr import math clr.AddReference('RevitAPI') clr.AddReference('RevitAPIUI') from Autodesk.Revit.DB import * doc = __revit__.ActiveUIDocument.Document collector1 = FilteredElementCollector(doc) collector1.OfCategory(BuiltInCategory.OST_Views).WhereElementIsNotElementType() elSet1 = collector1.ToElements() #how many characters at the front we are removing (REMEMBER: space is a character too) charCount = 4 #what is the view type that you are querying myViewType = ViewType.FloorPlan filterPar1 = 'Production/Working' filterPar1Val = 'Production' i=0 t = Transaction(doc, 'Rename Views Title on Sheet') t.Start() #iterate over views for el in elSet1: if(not el.IsTemplate and el.CanBePrinted and el.ViewType == myViewType): #custom view property filter if(el.get_Parameter(filterPar1).AsString() == filterPar1Val): #make sure the view name has more characters than what we are removing if(len(el.ViewName) > charCount): curTitle = el.ViewName print 'Old Name = ' + el.ViewName newTitle = curTitle.replace(curTitle[:charCount], '') print 'New Name = ' + newTitle el.get_Parameter('Title on Sheet').Set(newTitle) i+=1 t.Commit() print i.ToString() + ' views were updated'