Get all view templates

<p style=“text-align: left;”>I’m trying to get all view templates in a file.</p>
<p style=“text-align: left;”>I don’t understand why this code doesn’t work.</p>
<p style=“text-align: left;”></p>

<table>
<tbody>
<tr>
<td>import clr
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *
import Autodeskclr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument
views = FilteredElementCollector(doc).OfClass(View)
viewlist = list()
for view in views:
if view.IsTemplate == True:
viewlist.append(view)
OUT = viewlist</td>
</tr>
</tbody>
</table>

Hi Antony Mcphee, i think your code is ok when use method if view.IsTemplate == True, just one thing’s not yet right in your code is : INDENT in your code.

Thanks @Antony_Mcphee for the start, I found a few items in the header that were mixed up and characters not functioning. Try this. My first test has nulls, so need to review further. Get List of All View Templates.

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import Autodesk
clr.AddReference('RevitServices')
from RevitServices.Persistence import *
import RevitServices
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

doc = DocumentManager.Instance.CurrentDBDocument
views = FilteredElementCollector(doc).OfClass(View)
viewlist = list()

for view in views:
	if view.IsTemplate == True:
		viewlist.append(view)

#Assign your output to the OUT variable.
OUT = viewlist
2 Likes

as much as I’m learning to love :heartpulse: python archilab has a great solution for this

image

1 Like

yes, but those do not create a list of view templates. you have to pick them one at a time. not useful for my workflow. I did come across those in my search. Desired output was a list though.

well i guess you could go round about, and get all views, then put them through “is view template” node.

Edit: I was incorrect, the nodes listed above do provide a list of the view templates in the project file.

I stand corrected, not enough coffee yet I guess. Thank you.

1 Like

glad I could help

Would you be able to elaborate a bit further on how to use GetByType node to retrieve view templates?

from the archilab package you can use View Type and View.GetByType check out this forum post for more details