Last active
November 12, 2023 22:43
-
-
Save gtalarico/5882e36e97fb8fd89eb29ec7b79d23cc to your computer and use it in GitHub Desktop.
RevitAPI::Working Tools::Open Schedule in Excel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Copyright (c) 2016 Gui Talarico | |
Base script taken from pyRevit Respository. | |
pyRevit Notice | |
################################################################# | |
See this link for a copy of the GNU General Public License protecting this package. | |
https://github.com/eirannejad/pyRevit/blob/master/LICENSE | |
""" | |
from Autodesk.Revit.DB import ViewSchedule, ViewScheduleExportOptions | |
from Autodesk.Revit.DB import ExportColumnHeaders, ExportTextQualifier | |
from Autodesk.Revit.DB import BuiltInCategory, ViewSchedule | |
from Autodesk.Revit.UI import TaskDialog | |
import os | |
import subprocess | |
doc = __revit__.ActiveUIDocument.Document | |
uidoc = __revit__.ActiveUIDocument | |
desktop = os.path.expandvars('%temp%\\') | |
vseop = ViewScheduleExportOptions() | |
selected_ids = uidoc.Selection.GetElementIds() | |
if not selected_ids.Count: | |
'''If nothing is selected, use Active View''' | |
selected_ids=[ doc.ActiveView.Id ] | |
for element_id in selected_ids: | |
element = doc.GetElement(element_id) | |
if not isinstance(element, ViewSchedule): | |
print('No schedule in Selection. Skipping...') | |
continue | |
filename = "".join(x for x in element.ViewName if x not in ['*']) + '.txt' | |
element.Export(desktop, filename, vseop) | |
print('EXPORTED: {0}\n TO: {1}\n'.format(element.ViewName, filename)) | |
EXCEL = r"C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE" | |
if os.path.exists(EXCEL): | |
print('Excel Found. Trying to open...') | |
print('Filename is: ', filename) | |
try: | |
full_filepath = os.path.join(desktop, filename) | |
os.system('start excel \"{path}\"'.format(path=full_filepath)) | |
except: | |
print('Sorry, something failed:') | |
print('Filepath: {}'.filename) | |
print('EXCEL Path: {}'.format(EXCEL)) | |
else: | |
print('Could not find excel. EXCEL: {}'.format(EXCEL)) | |
print('Done') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment