Hi everyone, I am trying write a script that to extract data from bulk revit files.
What I am expect to do is open one revit file->get data (warnings and groups) from the file-> close file->open another one revit file and do the same.
However, I get an error from my script as shown below image and code. If I only extract warnings, the script is smooth without error, but when I try to extract group list as well. The error appear.
Can anyone help me to solve the problem? Thank you!
Code:
import clr, System
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('System')
from System.Collections.Generic import List
# Open and save Options
openoption = OpenOptions()
openoption.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets
# Current Document
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
# Preparing Input
docpaths = IN[0] if isinstance(IN[0], list) else [IN[0]]
# Variables
warning_list = []
group_list = []
# Function
def get_element_class(ofclass):
i = FilteredElementCollector(doc).OfClass(ofclass).WhereElementIsNotElementType().ToElements()
return i
# Core Data Processing
for document in docpaths:
modelpath = FilePath(document)
doc = app.OpenDocumentFile(modelpath, openoption)
# Warnings
warnings = doc.GetWarnings()
for warning in warnings:
warning_list.append(warning.GetDescriptionText())
# Group
groups = get_element_class(Group)
group_list.append(groups)
doc.Close(False)
OUT = warning_list, group_list