Create View Template from View?

Does anyone know if it is possible to create a view template from an existing view with Dynamo? It appears that the Revit API would allow it. See image below. Are there already any nodes and/or packages to achieve this?

That’s a “postable command” in Revit. Which means you are essentially sending that keypress / command to the revit application.

So all it will really do is this,

But here is the python if you want it,

import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *

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

output = []
pCmd = RevitCommandId.LookupPostableCommandId(PostableCommand.CreateTemplateFromCurrentView)
if IN[0] == True:
	uiapp.PostCommand(pCmd)
	output = True
else :
	output = 'set runit to true'
OUT = output
4 Likes

Thank you @john_pierson for the quick and informative reply. While it is not exactly what I was looking for I could probably use this in my workflow if the script could be modified to accept a selected view other than the current view. Do you know if that would be possible?

I’m not too sure. Perhaps others can chime in?

There is no API for creating a view template. The best you can do is to copy the existing view template, and then override its properties to make it do what you want. I mean, view template is just a view, so you can set it’s graphical overrides and then change which parameters are being controlled. All in all, it’s a dirty workaround, but that’s how you can achieve it.

1 Like

There is now :smiley:
https://www.revitapidocs.com/2020/84f4d0e3-ae49-c2f8-d7d3-53d120fe3223.htm

1 Like

do you have any python script for that?

You can use the View CreateViewTemplate node of the Genius Loci package.

here is an example. I created a new view based on level and active View, then new View Template and changed its name, then deleted the View.

bingo=doc.ActiveView.GetTypeId()
newLevel2=Level.Create(doc,3)

newView2= ViewPlan.Create(doc,bingo,newLevel2.Id)

#here is the creation of the new view template
viewTemplate2=newView2.CreateViewTemplate()

viewTemplate2.Name="New view template"

doc.Delete(newLevel2.Id)
2 Likes