Apply View Template to a List of Views in Excel File

I am very new to using Dynamo, but I have re-created a graph used to create views and place these on newly created sheets based on inputs from an Excel file. I would like to incorporate 3 additional inputs.

These inputs are as follows:

  1. Apply a View Template to the newly created views based on the Excel file (testing 3 different templates).
  2. Apply a scope box to a specific view based on the Excel file.
  3. Select the correct parameter in the keyplan based on the scope box or part of the sheet number (i.e. A-101B with B being the section of the building to be highlighted in the keyplan).

Python Script for ‘Make Sheets’:
#Make Sheets
import clr
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *

clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
sheetnames = IN[0]
sheetnumbers = IN[1]
titleblock = UnwrapElement(IN[2]) #unwrapped titleblock
sheetlist = list()

TransactionManager.Instance.EnsureInTransaction(doc) # you need an active transaction as you will create elements

for number in range(len(sheetnumbers)):
newsheet = ViewSheet.Create(doc,titleblock.Id)# create a new sheet where titleblock.Id is the id of the titleblock
newsheet.Name = sheetnames[number]
newsheet.SheetNumber = sheetnumbers[number]
sheetlist.append(newsheet.ToDSType(False))

TransactionManager.Instance.TransactionTaskDone()
OUT = sheetlist

Python Script for ‘Put View on Sheet’:
#Put view on sheet
import clr
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *

clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
sheets = IN[0]
views = IN[1]
x = IN[2]
y = IN[3]
viewsplaced = list()

TransactionManager.Instance.EnsureInTransaction(doc) # you need an active transaction as you will create elements

for number in range(len(sheets)):
sheet = UnwrapElement(sheets[number])
view = UnwrapElement(views[number])
Viewport.Create(doc,sheet.Id,view.Id,XYZ(x,y,0))
viewsplaced.append(view.ToDSType(False))

TransactionManager.Instance.TransactionTaskDone()
OUT = viewsplaced

Adding graph for further review.

CreateViewsSheetsPlace.dyn (31.4 KB)

Hello @Goldenb42 - Welcome to the forums!

I’ve got you part of the way there - refer to attached graph. I’m using Python as you want to build your data from Excel, but there are many great packages out there that contain dropdown nodes to help this too, such as Rhythm and Archi-Lab.

One thing to note, when you are pasting code in here you can copy it in correctly by typing (And removing of spaces):

[ CODE ]
Code goes here
[ /CODE ]

So I’ve solved your first two sections - Will let you have a go at the last one! If you can’t figure it out, please do ask for more help here :slight_smile:

What you see below is as follows:

  1. We can set any Parameter that shows itself in Revit by using the Element.SetParameterValueByName node (Very versatile!). The thing to note here is that some inputs, rather than being text (string) or numbers (integer/double), are Elements themselves. This is true for both the Scope Boxes and View Templates
  2. No out-of-the-box nodes exist to collect these two elements based on an input of a String, so we turn to Python. We have two Python Nodes here: #1 Collects your chosen View Templates and #2 collects your chosen Scope Boxes
  3. We simply input the relevant Strings from Excel here and voila - it works!
  4. We also utilize Lacing here to input into single node.

The two parts of Python I have put in here are as follows - One to collect our View Templates:

"""
Collecting only the Relevant View Templates based
on your Excel input.
"""
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

viewTemplateNames = IN[0]

if isinstance(viewTemplateNames, list):
    viewTemplateNames = IN[0]
else:
    viewTemplateNames = [IN[0]]

coll = FilteredElementCollector(doc).OfClass(View).ToElements()

results = []

for name in viewTemplateNames:
    for view in coll:
        if view.Name == name:
            results.append(view)

OUT = results

And one to collect our Scope Boxes:

"""
Collecting only the relevant Scope Boxes based
on your Excel input.
"""
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

scopeBoxNames = IN[0]

if isinstance(scopeBoxNames, list):
    scopeBoxNames = IN[0]
else:
    scopeBoxNames = [IN[0]]

coll = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_VolumeOfInterest).ToElements()

results = []

for name in scopeBoxNames:
    for view in coll:
        if view.Name == name:
            results.append(view)

OUT = results

Hope that gets you off to a start!

CreateViewsSheetsPlace-SA.dyn (63.6 KB)

1 Like

This is fantastic! I will give it a try and let you know what I come up. Thank you so much!

1 Like