Has anyone come across, or created a script that can export all drafting views from a detail container file? I am trying to make the move to the Autodesk Content Catalog and have all views be searchable in there rather than opening and upgrading our detail container file every time someone needs to place a detail in a future version of revit, and since the content catalog have version management I figured it was worth a shot to ask.Saving out 400+drafting views from revit to individual files can be quite the time suck… Thanks in advance… I have been fighting and starting over for like 2 hours on this and made zero progress
The exact method is not available in the API (at least not as far as I know).
However I believe you can utilize methods to create a new document from a file with minimal contwnt (ok no content) , and then copy a view from the current file into the new document, and save the new file as the view’s name.
I am not sure of any nodes or packages for this, but it is not too complex a Python script to write.
This Revit API forum post should give you some direction: Solved: Re: "Save to New File..." - Autodesk Community.
If they don’t have to be edited in your new project(s) you could make them DWGs and import those into your new project(s).
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
Just a thought. Why not have the views loaded in a project template file that everyone uses when starting a new project? Even 400+ drafting views, shouldn’t impact the file size that much. It would be a one time upgrade of all of the views when they start the project using the template file and then when the project is done, purge out any unused views.
EDIT: Or to elaborate on @bvs1982 suggestion. If they are permanent details, then export all out to separate dwg’s. Then you could set up a dynamo script similar to mimic a detail library and import the dwg back into a drafting/legend view by user selection.