Setting View Template Includes

Is it possible to set the Includes in a view template through Dynamo? Includes being the overall category check boxes, before you even get into things like model elements or annotation elements. If so what nodes should I be looking at? I’ve seen quite a bit on applying templates to views and the like but haven’t run across anything to control things at a top level.

5 Likes

I don’t think the API has access to those properties unfortunately. View Templates are a little limited when it comes to the API. They function fine as views but there’s not much you can do with the View Template specific stuff.

1 Like

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

22 Likes

Hello @Konrad_K_Sobon,

We are trying to activate or desactivate some includes boxes according to each view template. We have a problem at the beginning of the script.

Could you explain a little bit better what do you mean with: When you query the ViewTemplate for all parameter ids that can be controlled ?? How I get all those ids?

Are the ids different for each project or if the ViewTemplate have the same name and properties then keep the id? We assume the ids parameters are common for all view templates, but we are not 100% sure about it.

By the way, i don’t have the same View Type and View.GetByType nodes as in the picture attached. Which version did you use of archi-lab package?

Thanks in advance!

Oh you can get that list by calling this method on the view template:

http://www.revitapidocs.com/2018.1/64761c8c-ed01-65b6-2b05-ebd7b02acd77.htm

The ids with the “-” negative sign in front of them are system parameter ids and they would not differ between projects but all other Ids can potentially refer to different parameters and can potentially be different across models.

The two nodes are from Archi-Lab.net package. Get the latest version from Package Manager and it should have that.

Cheers!

I’m newbie at this, not so sure how I have to insert that on a script node.

ViewTemplateIncludeID

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

ElementId = UnwrapElement(IN[0])

ElementId = GetTemplateParameterIds As IList(Of ElementId)

#Assign your output to the OUT variable.
OUT = 0

How I should edit the API code on a script for Revit 2016?

Thanks!

I added this to archi-lab.net package:

it will be in version 2018.0.9

4 Likes

Hi @Konrad_K_Sobon

We downloaded the new version of archi-lab.net package, it works as it suposses to be, but it just give us back an ID list as string, maybe that’s the reason why it doesn’t work as we need to.

I guess the python node needs those IDs input as a real element ID (green background), or we missed something copying the python script.

Boolean as FALSE:
ViewTemplateIncludeID2

It doen’t report any error but apparently it doesn’t change parameter in revit.

Boolean as TRUE:
ViewTemplateIncludeID3

In case the python node needs Input 1 as real element (ID green background), how could we get that done?

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;

THANKS!

1 Like

I’m trying to do something similar but all I need is the current status of the ‘include’ parameter (i.e. True or False) - I’ve been looking at the scripts above by I really don’t understand the Python code to be able to figure out what is going on… :cry:

1 Like

Have a look at the latest archi-lab.net package. It should have some more useful nodes in there.

3 Likes

Nice work. That will allow me to cross another item off my list when I can a few hours.

Don’t let it be said I’m not one to try and push my luck but any idea how to drill down another level and look at the visibility/graphics settings etc for the template? I suspect that will be something of a can of worms and likely not possible…

There are some things in there that I suspect are possible. For example what Categories are on/off should be available. Filters should be available. I don’t think we can get much from Design Options or Linked Model visibility overrides.

Ps. Let’s move this conversation to a new topic. The original question was already answered.

2 Likes