Importing Drafting Views from external files to current document

Hi Dynamo users,

I have more than 700 files, each with a drafting view inside. Trying to merge 'em into one Revit file using the script below. But, there’s a glitch. When I copy those drafting views, they’re coming up empty in Revit. Does anyone know where the problem is?

Ah yes, this is because you are only copying the views and not the contents of the views.

There are threads on this forum for this which i can find for you when i return to a computer.

1 Like

I wasn’t able to find the thread i was looking for so i leave you with this which i use.
the Python for the import excel and find views will need to be substituted for the OOTB nodes but leave you to figure that out :stuck_out_tongue:

I can provide this as a help to you which are part of the excle view collection node.

Imports, there are more here than required for your purposes, so slim them down where you need to;

Good Luck!

#╦╔╦╗╔═╗╔═╗╦═╗╔╦╗╔═╗
#║║║║╠═╝║ ║╠╦╝ ║ ╚═╗
#╩╩ ╩╩  ╚═╝╩╚═ ╩ ╚═╝ IMPORTS
#==================================================================
import clr
import sys
import System
import RevitServices
import Autodesk
import Revit
import os
import time

clr.AddReference('RevitServices')
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')
clr.AddReference('System')
clr.AddReference('RevitAPI')
clr.AddReference("RevitNodes")
clr.ImportExtensions(Revit.Elements)
clr.AddReference('Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c')

from RevitServices.Persistence import DocumentManager
from Autodesk.Revit.DB import *
from System.Drawing import Point, Font
from System.Windows.Forms import OpenFileDialog
from System.Collections.Generic import List
from System import Environment
from System.Collections.Generic import List
from Microsoft.Office.Interop import Excel
from System.Runtime.InteropServices import Marshal
from System import Array
try:
    from System.Reflection import BindingFlags
except:
    clr.AddReference("System.Reflection")
    from System.Reflection import BindingFlags
#╔═╗╔═╗╦  ╦  ╔═╗╔═╗╔╦╗  ╦  ╦╦╔═╗╦ ╦╔═╗
#║  ║ ║║  ║  ║╣ ║   ║   ╚╗╔╝║║╣ ║║║╚═╗
#╚═╝╚═╝╩═╝╩═╝╚═╝╚═╝ ╩    ╚╝ ╩╚═╝╚╩╝╚═╝ COLLECT DRAFTING VIEWS
#==================================================================
#Collect the drafting views we want to copy accross

#It is important to unserstand here that the expected input lists of
#xclSheetsRequired = XXX."Actual Sheet Name" + "White spaces"

draftingCollector = FilteredElementCollector(SourceDoc).OfClass(ViewDrafting).ToElements()

draftingViews = list()

for d in draftingCollector:
    if d.IsTemplate != True:
        draftingViews.append(d)

# Assign your output to the OUT variable.
#OUT = draftingViews

xclSheetName = xclDataListsTransposed[0]
xclSheetRequired = xclDataListsTransposed[1]
xclSheetsToTransfer = []  # Output list for sheets
checkedCurrentDrawings = []  # Output list for modified draftingViews
matchingIndices = []  # Output list for matching indices
matchingDraftingViews = []  # Output list for matching drafting views

for name, required in zip(xclSheetName, xclSheetRequired):
    if isinstance(required, str):
        xclSheetsToTransfer.append(name)

# Remove characters before and including the first dot in xclSheetsToTransfer
xclSheetsToTransfer = [name.split(".", 1)[1].rstrip() if "." in name else name for name in xclSheetsToTransfer]

# Retrieve element names from draftingViews and modify strings
for view in draftingViews:
    view_name = view.Name
    modified_view_name = view_name.split(".", 1)[1].rstrip() if "." in view_name else view_name
    checkedCurrentDrawings.append(modified_view_name)

# Compare xclSheetsToTransfer with checkedCurrentDrawings and store matching indices
for i, name in enumerate(xclSheetsToTransfer):
    if name in checkedCurrentDrawings:
        matchingIndices.append(checkedCurrentDrawings.index(name))
        matchingDraftingViews.append(draftingViews[checkedCurrentDrawings.index(name)])
        
draftingViews = matchingDraftingViews

# Collect existing drafting views
draftingCollectorCurrent = FilteredElementCollector(doc).OfClass(ViewDrafting).ToElements()

# Get the names of existing drafting views
existingDraftingViewNames = [view.Name for view in draftingCollectorCurrent]

# Remove items from draftingViews that already exist
draftingViews = [view for view in draftingViews if view.Name not in existingDraftingViewNames]


#╔═╗╔═╗╦  ╦  ╔═╗╔═╗╔╦╗  ╔═╗╔═╗╔╗╔╔╦╗╔═╗╔╗╔╔╦╗╔═╗
#║  ║ ║║  ║  ║╣ ║   ║   ║  ║ ║║║║ ║ ║╣ ║║║ ║ ╚═╗
#╚═╝╚═╝╩═╝╩═╝╚═╝╚═╝ ╩   ╚═╝╚═╝╝╚╝ ╩ ╚═╝╝╚╝ ╩ ╚═╝ CONTENTS OF VIEWS
#==================================================================
#Get contents off views, but ignore the view itself

views = [UnwrapElement(view) for view in draftingViews] if isinstance(draftingViews, list) else [UnwrapElement(draftingViews)]

draftingViewContents = [FilteredElementCollector(SourceDoc, v.Id).ToElements() for v in views]

draftingViewContents = [contents[1:] for contents in draftingViewContents]


#OUT = draftingViews, draftingViewContents
end_time = time.time()
execution_time = end_time - start_time
execution_time_formatted = "{:.2f} Seconds".format(execution_time)

# Prepare the output
Xtime = []
Xtime.append("Execution time: {}".format(execution_time_formatted))

OUT = SourceDoc, draftingViews, draftingViewContents, Xtime,

Hi @semamzadehei i had some issue with copydraftingviewfromdocuments as well…, but seems copyelementsfromdocuments works for drafting view as well…but probably becourse you feed in a familydocument guess it should be revitapplication.document…try as here…

EDIT after a test seems its only copy the view empty

allright now it works…seems its the collector there gives trouble, if you collect the views with genius loci it works at least for me…in 2024