def testParameterTemplate(self): wall = _(self.fixture.createWall()) info = _(revitron.DOC.ProjectInformation) with revitron.Transaction(): wall.set('param1', 'Test & Text').set('param2', 10, 'Integer') info.set('projectParam', 'Project Name') self.assertEquals( 'Project_Name: Test_Text-10', revitron.ParameterTemplate( wall.element, '{%projectParam%}: {param1}-{param2}').render()) self.assertEquals( 'Project Name: Test & Text-10', revitron.ParameterTemplate(wall.element, '{%projectParam%}: {param1}-{param2}', False).render())
def exportSheet(self, sheet, directory, unit, template=False): """ Exports a sheet. Args: sheet (object): A Revit sheet directory (string): The export directory unit (object): The `export unit <https://www.revitapidocs.com/2020/1d3eb4f4-81d2-10a6-3eab-4a9c20e39053.htm>`_ template (string, optional): A name template. Defaults to '{Sheet Number}-{Sheet Name}'. Returns: string: The path of the exported PDF. False on error. """ import revitron if revitron.Element(sheet).getClassName() != 'ViewSheet': revitron.Log().warning('Element is not a sheet!') return False if not directory: revitron.Log().warning('There is no DWG export directory defined!') sys.exit() if not template: template = '{Sheet Number}-{Sheet Name}' fullPath = os.path.join( directory, revitron.ParameterTemplate(sheet, template).render() + '.dwg') path = os.path.dirname(fullPath) file = os.path.basename(fullPath) if not os.path.exists(path): os.makedirs(path) db = revitron.DB self.options.MergedViews = True self.options.TargetUnit = unit success = revitron.DOC.Export(path, file, List[db.ElementId]([sheet.Id]), self.options) if success: return fullPath return False
def exportSheet(self, sheet, directory, template=False): """ Exports a sheet. Args: sheet (object): A Revit sheet directory (string): The export directory template (string, optional): A name template. Defaults to '{Sheet Number}-{Sheet Name}'. Returns: bool: False on error, True on success """ import revitron if revitron.Element(sheet).getClassName() != 'ViewSheet': print(':face_with_rolling_eyes: Element is not a sheet!') return False if not directory: directory = self.output if not template: template = '{Sheet Number}-{Sheet Name}' fullPath = os.path.join( directory, revitron.ParameterTemplate(sheet, template).render() + '.dwg') path = os.path.dirname(fullPath) file = os.path.basename(fullPath) if not os.path.exists(path): os.makedirs(path) db = revitron.DB self.options.MergedViews = True self.options.TargetUnit = db.ExportUnit.Default success = revitron.DOC.Export(path, file, List[db.ElementId]([sheet.Id]), self.options) if success: return fullPath return False
def exportSchedule( self, schedule, directory, template=False, delimiter=';', hasTitle=False ): """ Exports a schedule. Args: schedule (object): A Revit schedule directory (string): A custom output directory. Defaults to False. template (string, optional): A name template. Defaults to '{View Name}'. delimiter (string, optional): A csv delimiter. Defaults to ';'. hasTitle (bool, optional): Set True to export schedule title. Defaults to False. Returns: string: The path of the exported CSV. False on error. """ import revitron if revitron.Element(schedule).getClassName() != 'ViewSchedule': revitron.Log().warning('Element is not a schedule!') return False if not directory: revitron.Log().warning('No directory specified!') return False if not template: template = '{View Name}' name = revitron.ParameterTemplate(schedule, template).render() + '.csv' if not os.path.exists(directory): os.makedirs(directory) options = revitron.DB.ViewScheduleExportOptions() options.FieldDelimiter = delimiter options.Title = hasTitle options.TextQualifier = revitron.DB.ExportTextQualifier['None'] schedule.Export(directory, name, options) file = os.path.join(directory, name) return file
def printSheet(self, sheet, size, orientation='Landscape', directory=False, template=False): """ Prints a sheet. Args: sheet (object): A Revit sheet size (string): A size name like A0 or A4 orientation (string, optional): The orientation, 'Landscape' or 'Portrait'. Defaults to 'Landscape'. directory (string, optional): A custom output directory. Defaults to False. template (string, optional): A name template. Defaults to '{Sheet Number}-{Sheet Name}'. Returns: bool: False on error, True on success """ import revitron if revitron.Element(sheet).getClassName() != 'ViewSheet': print(':face_with_rolling_eyes: Element is not a sheet!') return False if not directory: directory = self.output if not template: template = '{Sheet Number}-{Sheet Name}' path = os.path.join( directory, revitron.ParameterTemplate(sheet, template).render() + '.pdf') if not os.path.exists(os.path.dirname(path)): os.makedirs(os.path.dirname(path)) transaction = revitron.Transaction() viewSet = revitron.DB.ViewSet() viewSet.Insert(sheet) viewSheetSetting = self.manager.ViewSheetSetting viewSheetSetting.CurrentViewSheetSet.Views = viewSet viewSheetSetting.SaveAs("_temp_") self.manager.PrintSetup.SaveAs("_temp_") self.manager.Apply() orientation = getattr(revitron.DB.PageOrientationType, orientation) # Set current print page settings. printParameters = self.manager.PrintSetup.CurrentPrintSetting.PrintParameters printParameters.ZoomType = revitron.DB.ZoomType.Zoom printParameters.Zoom = 100 printParameters.PaperPlacement = revitron.DB.PaperPlacementType.Center printParameters.PageOrientation = orientation printParameters.PaperSize = self.sizes[size] printParameters.RasterQuality = revitron.DB.RasterQualityType.High # Set in-session print settings. printParameters = self.manager.PrintSetup.InSession.PrintParameters printParameters.ZoomType = revitron.DB.ZoomType.Zoom printParameters.Zoom = 100 printParameters.PaperPlacement = revitron.DB.PaperPlacementType.Center printParameters.PageOrientation = orientation printParameters.PaperSize = self.sizes[size] printParameters.RasterQuality = revitron.DB.RasterQualityType.High # Again save settings. try: self.manager.PrintSetup.Save() except: self.manager.PrintSetup.SaveAs("_temp2_") self.manager.Apply() self.manager.SubmitPrint(sheet) viewSheetSetting.Delete() transaction.rollback() # Move file form temp output to directory. timePassed = time.time() moved = False while (time.time() - timePassed) < 30 and not moved: time.sleep(0.5) tempFiles = glob.glob(self.tempOutputPattern(sheet)) if tempFiles: tempFile = tempFiles[0] time.sleep(2) if os.access(tempFile, os.W_OK): try: shutil.move(tempFile, path) moved = True except: pass if moved: return path return False
def name(self): return revitron.ParameterTemplate(self.item, '{Family Name} - {Type Name}', False).render()