Is it possible to duplicate a view template?
I´ve tryed to duplicate a view template with the node View.Duplicate From Clockwork but it seams it works only to views, not with view templates.
Thank you for helping.
J
Is it possible to duplicate a view template?
I´ve tryed to duplicate a view template with the node View.Duplicate From Clockwork but it seams it works only to views, not with view templates.
Thank you for helping.
J
Hi @Jose_Goncalves ,
you can’t use the duplicate method on viewtemplates, but you can use CopyElements method from ElementTransformUtils class :
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import Autodesk
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import*
doc = DocumentManager.Instance.CurrentDBDocument
if isinstance(IN[0],list):
views = UnwrapElement(IN[0])
else:
views = [UnwrapElement(IN[0])]
ids = [view.Id for view in views]
elementlist = List[ElementId](ids)
TransactionManager.Instance.EnsureInTransaction(doc)
for view in views:
copyid = ElementTransformUtils.CopyElements(doc, elementlist, doc, Transform.Identity, CopyPasteOptions())
newview = [doc.GetElement(id) for id in copyid]
TransactionManager.Instance.TransactionTaskDone()
OUT = newview
Thank you Mostafa, it did work!!!
I must have a view with a template assign in order to get a new view template right?
@Jose_Goncalves You could do something like this, but it wont work for 3D-view templates because of this bug: https://github.com/DynamoDS/Dynamo/issues/2970
Einar,
I was looking to duplicate element view templates that are not assign to views.
It seams that it’s not possible I have to create some views with some template views assigned, then with this pyton script is possible to replicate a template and then of course rename it.
Tanks anyhow.
J
Einar is right . Document.Views node from Clockwork will get all views ANDview templates, even if they are not assigned to a view. What he does next is filtering the view templates using view.isviewtemplate , then he gets the view template by name with string.contains and filter.byboolmask . You hould give it a try
There’s a node in Node-Mode that does exactly the same thing… Just a little bit more conveinient :
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import*
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
views = FilteredElementCollector(doc).OfClass(View)
templatesid = [v.Id for v in views if v.IsTemplate == True]
collect = []
if isinstance(IN[0],list):
names = IN[0]
else:
names = [IN[0]]
for n in names:
for id in templatesid:
temp = doc.GetElement(id)
if temp.Name == n:
collect.append(temp)
templatesid.remove(id)
else:
continue
OUT = collect
Yes!!! Your Right and Einar is Right!!! Thank you both. Don’t Know why it didn’t work the first time.
It did work, i’m involved in a process of creating nodes custum nodes for automatic documents, and creating new view template names was an essencial step.
You guys are a big help.
Thank’s Einar your suggestion made it work.
J
This works great for duplicating templates, but how would I rename the templates in python as they are created?
I have tried renaming the view templates after they have been created but the Name parameter doesnt exist for templates and the Type Name parameter (Which appears to be the template name) is read only.
So could I rename the new templates as they are created using a list of names?
Got a bit further but lack of python experience letting me down
Im attempting to duplicate a standard starting template and rename the copies from a list of names.
"
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import Autodesk
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# 10
from System.Collections.Generic import*
if isinstance(IN[0],list):
views = UnwrapElement(IN[0])
else:
views = [UnwrapElement(IN[0])]
if isinstance(IN[1],list):
names = UnwrapElement(IN[1])
else:
names = [UnwrapElement(IN[1])]
newviews=[]
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)
#30
for view in views:
id= view.Id
newview = ElementTransformUtils.CopyElements(doc, doc.GetElement(id), doc, Transform.Identity, CopyPasteOptions())
newview.Name = names[view]
newviews.append(newview)
TransactionManager.Instance.TransactionTaskDone()
OUT = newviews;
";
Hi @Joseph_Peel ,
this should work for you :
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import Autodesk
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import*
if isinstance(IN[0],list):
views = [UnwrapElement(i) for i in IN[0]]
else:
views = [UnwrapElement(IN[0])]
if isinstance(IN[1],list):
names = [UnwrapElement(j) for j in IN[1]]
else:
names = [UnwrapElement(IN[1])]
doc = DocumentManager.Instance.CurrentDBDocument
ids = [view.Id for view in views]
elementlist = List[ElementId](ids)
newviews = []
TransactionManager.Instance.EnsureInTransaction(doc)
copyids = ElementTransformUtils.CopyElements(doc, elementlist, doc, Transform.Identity, CopyPasteOptions())
for id,name in zip(copyids,names):
newview = doc.GetElement(id)
newview.Name = name
newviews.append(newview)
TransactionManager.Instance.TransactionTaskDone()
OUT = newviews