Setting View Template Includes

@Chad_Clary,

Like @Nick_Boyts was saying, there is no API that allows you to set that in a very straight forward manner. Instead we can probably work around this a little. Here’s my findings:

When you query the ViewTemplate for all parameter ids that can be controlled the list might look like this:

Now, as you can see there are some ids that have “-” before the number and some that are more “regular”. The ids with a negative sign are predefined system parameters that we don’t really have access to. The other ones are probably Shared Parameters that were added to the project and View Category specifically. We can select them and do things to them. Later about that.

Now, there are exactly 27 system parameters which happens to be matching exactly how many parameters there are in the View Template UI in Revit. I am guessing that number will be the same for all Views. So, since I was bored I went through the list of these parameters and mapped them to their values in Revit:

Now, with a little bit of Python you can turn them on or off for a view template like this:

# Copyright(c) 2017, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net

import clr
# Import Element wrapper extension methods
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

# Import RevitAPI
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

import System
from System import Array
from System.Collections.Generic import *

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

if IN[2]:
	try:
	    errorReport = None
	    TransactionManager.Instance.EnsureInTransaction(doc)
	    
	    for i in IN[0]:
	    	update = False
	    	vt = UnwrapElement(i)
	    	allParams = [id.IntegerValue for id in vt.GetTemplateParameterIds()]
	    	exclude = set(IN[1])
	    	toSet = []
	    	for j in allParams:
	    		if j not in exclude:
	    			toSet.append(ElementId(j))
	    			update = True
	    	if update:
	    		sysList = List[ElementId](toSet)
	    		vt.SetNonControlledTemplateParameterIds(sysList)
	
	    TransactionManager.Instance.TransactionTaskDone()
	
	except:
	    # if error occurs anywhere in the process catch it
	    import traceback
	    errorReport = traceback.format_exc()
else:
	errorReport = "False"

# Assign your output to the OUT variable
if None == errorReport:
    OUT = 0
else:
    OUT = errorReport

Finally, back to those other parameters that I recognized as either project or shared parameters. If they are shared we can find them like so:

Put these together with the system ones in a list, and now you have full control of all parameters in your view template.

Cheers!

23 Likes