Get all view templates with Python

api
revit
dynamo

#1

Hi All,

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[0]==None gives me false!

Strangely if i get the name of the templates I can get the name from the null! :slightly_smiling_face:

OUT= [v.Name for v in viewTemplates]

image

Any idea why this is happening?


#2

May be like this:

templates = [v.Id for v in views if v.Name == None]


#3

@Kulkul that gives me and empty list. Also why are you trying to get the Id instead? What are you trying to do?

image


#4

Dynamo does not have an element wrapper for 3d view templates and those are instead directly converted to null


#5

Hi @salvatoredragotta

As @Dimitar_Venkov said we can’t collect 3d view templates but you can remove nulls from your list this way:

Cheers!


#6

@Kulkul I tested your solution but it just doesn’t get rid of 3D view templates but also section templates


#7

@salvatoredragotta Drop here your rvt file and show us the list of your result.


#8

@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;


#9

@salvatoredragotta is this what you need?

Capture


#10

@Kulkul Yes The list top left ! How did you filter?


#11

I used logic inside python.


#12

Thanks! Got it :smile:


#13

I was facing similar issue. This post has saved me. @Kulkul your life saver. Thanks a lot :slight_smile:


#14

Can share the final script please?