I’m trying to get all the view template in my project with the following code
views = FilteredElementCollector(doc).OfClass(View).ToElements()
viewTemplates=[v for v in views if v.IsTemplate]
I get some nulls in place of the 3D view templates but I cannot clean inside the Python script.
viewTemplates==None gives me false!
Strangely if i get the name of the templates I can get the name from the null!
OUT= [v.Name for v in viewTemplates]
Any idea why this is happening?
August 7, 2018, 1:42am
May be like this:
templates = [v.Id for v in views if v.Name == None]
@Kulkul that gives me and empty list. Also why are you trying to get the Id instead? What are you trying to do?
Dynamo does not have an element wrapper for 3d view templates and those are instead directly converted to null
August 7, 2018, 6:08am
@Dimitar_Venkov said we can’t collect 3d view templates but you can remove nulls from your list this way:
@Kulkul I tested your solution but it just doesn’t get rid of 3D view templates but also section templates
August 7, 2018, 11:37am
@salvatoredragotta Drop here your rvt file and show us the list of your result.
@Kulkul I’m using the sample project rac_basic_sample_project.rvt
I’ve created 3 new section template (b1,b2,b3).
There are the results;
August 7, 2018, 12:54pm
@salvatoredragotta is this what you need?
@Kulkul Yes The list top left ! How did you filter?
August 8, 2018, 5:21am
How did you filter?
I used logic inside python.
September 3, 2018, 1:59pm
I was facing similar issue. This post has saved me.
@Kulkul your life saver. Thanks a lot
Can share the final script please?
A slight modification to the python code above using the instance function.
# Import libraries.
from Autodesk.Revit.DB import*
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# Get view templates.
view_templates = [t for t in FilteredElementCollector(doc).OfClass
(View).ToElements() if t.IsTemplate and not isinstance(t, View3D)]
# Assign your output to the OUT variable.
OUT = view_templates