def create_file_dialog(dialog_type, directory, allow_multiple, save_filename, file_types, uid): window = BrowserView.instances[uid] if not directory: directory = os.environ['HOMEPATH'] try: if dialog_type == FOLDER_DIALOG: dialog = WinForms.FolderBrowserDialog() dialog.RestoreDirectory = True if directory: dialog.SelectedPath = directory result = dialog.ShowDialog(window) if result == WinForms.DialogResult.OK: file_path = (dialog.SelectedPath, ) else: file_path = None elif dialog_type == OPEN_DIALOG: dialog = WinForms.OpenFileDialog() dialog.Multiselect = allow_multiple dialog.InitialDirectory = directory if len(file_types) > 0: dialog.Filter = '|'.join([ '{0} ({1})|{1}'.format(*parse_file_type(f)) for f in file_types ]) else: dialog.Filter = localization[ 'windows.fileFilter.allFiles'] + ' (*.*)|*.*' dialog.RestoreDirectory = True result = dialog.ShowDialog(window) if result == WinForms.DialogResult.OK: file_path = tuple(dialog.FileNames) else: file_path = None elif dialog_type == SAVE_DIALOG: dialog = WinForms.SaveFileDialog() dialog.Filter = localization[ 'windows.fileFilter.allFiles'] + ' (*.*)|' dialog.InitialDirectory = directory dialog.RestoreDirectory = True dialog.FileName = save_filename result = dialog.ShowDialog(window) if result == WinForms.DialogResult.OK: file_path = dialog.FileName else: file_path = None return file_path except: logger.exception('Error invoking {0} dialog'.format(dialog_type)) return None
def loadRoot(self): # Ask the user which folder to analyse folderDialog = Forms.FolderBrowserDialog() folderDialog.ShowNewFolderButton = False folderDialog.SelectedPath = "c:\\" folderDialog.Description = "Please select the folder to analyse" if folderDialog.ShowDialog() != Forms.DialogResult.OK: return False self.fsRoot = DiskDir(folderDialog.SelectedPath, None, None) self.flKeeper.Refresh(self.fsRoot) return True
def create_file_dialog(self, dialog_type, directory, allow_multiple, save_filename): if not directory: directory = os.environ["HOMEPATH"] try: if dialog_type == FOLDER_DIALOG: dialog = WinForms.FolderBrowserDialog() dialog.RestoreDirectory = True result = dialog.ShowDialog(BrowserView.instance.browser) if result == WinForms.DialogResult.OK: file_path = (dialog.SelectedPath, ) else: file_path = None elif dialog_type == OPEN_DIALOG: dialog = WinForms.OpenFileDialog() dialog.Multiselect = allow_multiple dialog.InitialDirectory = directory dialog.Filter = localization[ "windows.fileFilter.allFiles"] + " (*.*)|*.*" dialog.RestoreDirectory = True result = dialog.ShowDialog(BrowserView.instance.browser) if result == WinForms.DialogResult.OK: file_path = tuple(dialog.FileNames) else: file_path = None elif dialog_type == SAVE_DIALOG: dialog = WinForms.SaveFileDialog() dialog.Filter = localization[ "windows.fileFilter.allFiles"] + " (*.*)|" dialog.InitialDirectory = directory dialog.RestoreDirectory = True dialog.FileName = save_filename result = dialog.ShowDialog(BrowserView.instance.browser) if result == WinForms.DialogResult.OK: file_path = dialog.FileName else: file_path = None return file_path except: logger.exception("Error invoking {0} dialog".format(dialog_type)) return None
def pick_folder(): fb_dlg = Forms.FolderBrowserDialog() if fb_dlg.ShowDialog() == Forms.DialogResult.OK: return fb_dlg.SelectedPath
def main(): """Main script docstring.""" print("🐍 Running {fname} version {ver}...".format(fname=__name, ver=__version)) # STEP 0: Setup app = __revit__.Application doc = __revit__.ActiveUIDocument.Document uidoc = __revit__.ActiveUIDocument view = doc.ActiveView # STEP 1: Find all appropriate schedules print("Getting all available schedules from the model...", end="") all_schedules = db.FilteredElementCollector(doc)\ .OfCategory(db.BuiltInCategory.OST_Schedules)\ .WhereElementIsNotElementType()\ .ToElements() print("✔") print(" ➜ Found {num} schedules in the project.".format( num=len(all_schedules))) #print(all_schedules) # STEP 2: Filtering for quantification schedules (with given prefix) print("Filtering quantification schedules from the found schedules...", end="") quantity_schedules = [ s for s in all_schedules if s.Name.startswith(PREFIX) ] print("✔") print(" ➜ Found {num} schedules with prefix '{prefix}'.".format( num=len(quantity_schedules), prefix=PREFIX)) #print(quantity_schedules) # STEP 3: Ask for export folder location print("Please select an output folder for saving the schedules...", end="") folder_browser = swf.FolderBrowserDialog() folder_browser.Description = "Please select an output folder for saving the schedules." if folder_browser.ShowDialog( ) != swf.DialogResult.OK: # no folder selected print("\n✘ No folder selected. Nothing to do.") return ui.Result.Cancelled print("✔") print("🛈 Selected output folder: {folder}".format( folder=folder_browser.SelectedPath)) # STEP 3: Export all selected schedules # https://www.revitapidocs.com/2018/8ba18e73-6daf-81b6-d15b-e4aa90bc8c22.htm print("Exporting schedules as CSV to selected output folder...", end="") try: export_options = db.ViewScheduleExportOptions() export_options.FieldDelimiter = "," for schedule in quantity_schedules: file_name = "{name}.csv".format(name=schedule.Name) schedule.Export(folder_browser.SelectedPath, file_name, export_options) except Exception as ex: print("\n✘ Exception:\n {ex}".format(ex=ex)) return ui.Result.Failed else: print("✔\nDone. 😊") return ui.Result.Succeeded