Hers’s a python script to transfer Drafting Views based on Revit SDK Samples - Duplicate Views
I’ve used the standard template - I would suggest creating a stripped back template for this
From my limited testing you may extend this by also transferring the view settings such as scale etc.
This code has a subclassed interface handler IDuplicateTypeNamesHandler
it will only work in IronPython versions 2 or 3
import traceback
import clr
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
# Duplicate Type name handler
class HideAndAcceptDuplicateTypeNamesHandler(IDuplicateTypeNamesHandler):
def OnDuplicateTypeNamesFound(self, args):
return DuplicateTypeAction.UseDestinationTypes
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
# Paths
template = "C:\\ProgramData\\Autodesk\\RVT 2024\\Templates\\Default_M_ENU.rte"
out_path = "C:\\temp\\"
# Defaults
sao = SaveAsOptions()
sao.OverwriteExistingFile = True
copypasteoptions = CopyPasteOptions()
copypasteoptions.SetDuplicateTypeNamesHandler(HideAndAcceptDuplicateTypeNamesHandler())
# Drafting Views in current document
views = FilteredElementCollector(doc).OfClass(ViewDrafting).ToElements()
output = []
for view in views:
# Get and filter elements
collector = FilteredElementCollector(view.Document, view.Id)
collector.WherePasses(ElementCategoryFilter(ElementId.InvalidElementId, True))
elems = collector.ToElementIds()
# Create doc
new_doc = app.NewProjectDocument(template)
with Transaction(new_doc, "Transfer Drafting View") as t:
t.Start()
viewfamilytype = next(
vft
for vft in FilteredElementCollector(new_doc).OfClass(ViewFamilyType)
if vft.ViewFamily == ViewFamily.Drafting
)
try:
new_view = ViewDrafting.Create(new_doc, viewfamilytype.Id)
new_view.Name = view.Name
ElementTransformUtils.CopyElements(
view, elems, new_view, Transform.Identity, copypasteoptions
)
except Exception:
output.append(traceback.format_exc())
t.Commit()
filepath = out_path + new_view.Name + ".rvt"
new_doc.SaveAs(filepath, sao)
new_doc.Close(False)
output.append(filepath)
OUT = output