Duplicate views without ViewTemplate if none selected

Hi all,

I was wondering if someone could help me. I got a script that works partly.
It comes with an interface. When everything is filled in it works.

The user is supposed to select a ViewTemplate when he duplicates view(s).
Sometimes there is no ViewTemplate needed, but when the option ViewTemplate is left blank the script wont duplicate.

On the picture down here there is no viewtemplate selected List[0][1] = null

i tried this workaround, i m feeding the result in to the “View.ApplyViewTemplate” node from Steam Nodes.

which looks like this in python:

#template for python nodes in dynamo 1.0
#proposed by Julien Benoit @jbenoit44 
import clr
from Autodesk.DesignScript.Geometry import *
# Import ToDSType(bool) extension method
import Revit
# Import geometry conversion extension methods
# Import DocumentManager and TransactionManager
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
# Import RevitAPI
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

viewTempName = IN[1]
views = []
for i in IN[0]:

# Start Transaction

collector = FilteredElementCollector(doc).OfClass(View)
for i in collector:
	if i.IsTemplate == True and i.Name == viewTempName:
		viewTemp = i

for i in views:
	i.ViewTemplateId = viewTemp.Id

# End Transaction


Any help is greatly appriciated! :slight_smile:

Would you provide more of the graph and also so the node results and /or any error messages. It will help determine how we can help.

This is how I do it… Admittedly not in data shapes but maybe you can adapt… Perhaps an ‘active’ input is required?

Hope that’s helpful,


Thanks for the input. thats the problem :smiley:
as long the user inputs a viewtemplate from the dropdown they get on the interface the script works as desired.
But there is no option to choose “no template” because no template is not a template.
See picture below

Would PassThrough help in place of your code block?

How would that work? i think the Apply View Template desires the name of a viewtemplate.
How do i choose no template? i tried feeding it “” but that doesnt work.

the script works as long as the user chooses any template from the dropdown, just when its left out blank it wont duplicate.

Might not work…!

1 Like

Alternatively, rather than use your IF, try using the same code I am (from Clockwork)…

I have done something very similar in the past, but how I have dealt with it is to create / duplicate the views FIRST, then apply the template to it AFTER it has been created with a simple Element.SetParameterByName node. This allows you to “skip” the template if one is not selected. I know in this case I am “hard” selecting it, but it would be just as easy through the Data-Shapes.

@Mark.Ackerley I get what you are saying but thats not the point where it stops working.
How do i tell this node template:

Its from Steam Nodes, the python code is shown in my first post.

I can feed it any viewtemplate as string, it will work. but what if i dont want a viewtemplate?

@SeanP Thanks for your help, i came up with the same idea earlier. i think the problem is the node i use, needs viewtemplate as a string. so that wont work.

Could an option be to create a “default” view template and make that the default slection for the drop down? That way if they don’t pick one you still get something to work with? Perhaps you could also look for another view duplicate node that doesn’t require a VT.

1 Like

Wont it be possible to select <None.> somehow? it shows up in revit when you choose viewtemplate
If no VT selected the script returns null, i can change the null to anything afterwards, i just dont know how to call “no ViewTemplate” or None in Dynamo

See if you can make this work for you. May need a little python.

Yes -add a option to your list of keys, and a null to your list of values. The graph will throw an error at that node, but the views will be created. So long as you don’t need to process stuff down the line you should be all set.

If you want to avoid the error, you’ll need to work an if statement into your python to not perform any action of the valu passed is a null, and set the template if it’s a string.

Could you explain by using a picture, i dont think i fully understand :frowning:

Unfortunately, I have limited access to my laptop, and only have internet via my cell phone for the weekend.

Nodes that will help:

List.AddItemToFront; (two of these)
null in a code block;

1 Like

ok, ill try to adapt this. ill let you know if i succeed :slight_smile:

the Views.Duplicate doesnt seem to handle the null; value?

Maybe we should back up just a second. Are you trying to apply the VT to ONLY the duplicated views, or to both the existing and new? What you are doing in this graph would be applying the VT to the old BEFORE duplicating them.

However, the Null isn’t working because it can’t duplicate a “null” view. Try putting the template node AFTER the View.Duplicate node. This way if there isn’t a template the view will still be created.


thanks, i didnt even notice that was happening! applied that to my graph.

But still i m not able to copy with no template, i tried applying what @jacob.small posted earlyer. see pictures below.

Looks like maybe you should use this post for reference and @Konrad_K_Sobon’s package for existing nodes to do this work.

Once the views are duplicated, use an IF statement to either Apply the VT they selected, or remove it if they didn’t pick one. Would that work for you?