def get_source_sheets(): sheet_elements = forms.select_sheets(button_name='Select TitleBlocks', use_selection=True, include_placeholder=False) if not sheet_elements: script.exit() return sheet_elements
def get_source_sheets(): sheet_elements = forms.select_sheets(button_name='Copy Sheets') if not sheet_elements: sys.exit(0) return sheet_elements
def selected_sheets(self): """Property that retrieves selected views or promt user to select some from the dialog box.""" # FILTER SHEETS FROM SELECTION selected_sheets = [doc.GetElement(element_id) for element_id in uidoc.Selection.GetElementIds() if type(doc.GetElement(element_id)) == ViewSheet] # SELECT SHEETS IF NONE SELECTED IN UI if not selected_sheets : selected_sheets = forms.select_sheets(title="Select sheets to rename.", button_name="Rename selected sheets", width=1000) # FIXME replace with custom view selection box later... if not selected_sheets: forms.alert("No views were selected.\nPlease, try again.", exitscript=True, title=__title__) return selected_sheets
'selected sheet since they can not exist on multiple sheets. ' \ 'The command defaults to active view if no views are selected.' \ '\n\nShift+Click:\n' \ 'Pick source views from list instead of selection or active view.' logger = script.get_logger() selected_views = forms.select_views(use_selection=True) if selected_views: logger.debug('Selected views: {}'.format(len(selected_views))) # get the destination sheets from user dest_sheets = forms.select_sheets() if dest_sheets: logger.debug('Selected sheets: {}'.format(len(dest_sheets))) with revit.Transaction("Add Views to Sheets"): for selected_view in selected_views: for sheet in dest_sheets: logger.debug('Adding: %s', revit.query.get_name(selected_view)) try: DB.Viewport.Create(revit.doc, sheet.Id, selected_view.Id, DB.XYZ(0, 0, 0)) except Exception as place_err: logger.debug('Error placing view on sheet: {} -> {}'
revelids = [DB.ElementId(x) for x in addrevs] s.SetAdditionalRevisionIds(List[DB.ElementId](revelids)) affectedsheets.append(s) if len(affectedsheets) > 0: print('SELECTED REVISION REMOVED FROM THESE SHEETS:') print('-' * 100) for s in affectedsheets: snum = s.LookupParameter('Sheet Number').AsString().rjust(10) sname = s.LookupParameter('Sheet Name').AsString().ljust(50) print('NUMBER: {0} NAME:{1}'.format(snum, sname)) if len(cloudedsheets) > 0: print('SELECTED REVISION IS CLOUDED ON THESE SHEETS ' 'AND CAN NOT BE REMOVED.') print('-' * 100) for s in cloudedsheets: snum = s.LookupParameter('Sheet Number').AsString().rjust(10) sname = s.LookupParameter('Sheet Name').AsString().ljust(50) print('NUMBER: {0} NAME:{1}'.format(snum, sname)) revision = forms.select_revisions(button_name='Select Revision', multiselect=False) sheets = forms.select_sheets(button_name='Remove Revision') if revision and sheets: remove_rev_from_sheets(revision, sheets)
__doc__ = 'Select a revision from the list of revisions\n'\ 'and this script will remove that revision ' \ 'from all sheets if it has not been "clouded" on the sheet.' logger = script.get_logger() revisions = forms.select_revisions(button_name='Select Revision', multiple=True) logger.debug(revisions) if revisions: sheets = forms.select_sheets(button_name='Set Revision') if sheets: with revit.Transaction('Remove Revision from Sheets'): updated_sheets = revit.update.update_sheet_revisions(revisions, sheets, state=False) if updated_sheets: print('SELECTED REVISION REMOVED FROM THESE SHEETS:') print('-' * 100) cloudedsheets = [] for s in sheets: if s in updated_sheets: revit.report.print_sheet(s) else: cloudedsheets.append(s) else:
from pyrevit import revit, DB from pyrevit import forms from pyrevit import script __doc__ = 'Increases the sheet number of the selected sheets by one. '\ 'The sheet name change will be printed if logging is set '\ 'to Verbose in pyRevit settings.' logger = script.get_logger() selection = revit.get_selection() shift = 1 selected_sheets = forms.select_sheets(title='Select Sheets') if not selected_sheets: script.exit() sorted_sheet_list = sorted(selected_sheets, key=lambda x: x.SheetNumber) if shift >= 0: sorted_sheet_list.reverse() with revit.Transaction('Shift Sheets'): for sheet in sorted_sheet_list: try: cur_sheet_num = sheet.SheetNumber sheet_num_param = sheet.Parameter[DB.BuiltInParameter.SHEET_NUMBER] sheet_num_param.Set( coreutils.increment_str(sheet.SheetNumber, shift))
for exst_vp in exst_vps: if vport.ViewId == exst_vp.ViewId: exst_vp.SetBoxCenter(vport.GetBoxCenter()) exst_vp.ChangeTypeId(vport.GetTypeId()) return True return False selViewports = [] allSheetedSchedules = DB.FilteredElementCollector(revit.doc)\ .OfClass(DB.ScheduleSheetInstance)\ .ToElements() selected_sheets = forms.select_sheets(title='Select Target Sheets', include_placeholder=False, button_name='Select Sheets') # get a list of viewports to be copied, updated if selected_sheets and len(selected_sheets) > 0: if int(__revit__.Application.VersionNumber) > 2014: cursheet = revit.uidoc.ActiveGraphicalView for v in selected_sheets: if cursheet.Id == v.Id: selected_sheets.remove(v) else: cursheet = selected_sheets[0] selected_sheets.remove(cursheet) revit.uidoc.ActiveView = cursheet selected_vps = revit.pick_elements()
"""Remove selected revisions from selected sheets.""" from pyrevit import revit, DB from pyrevit import forms from pyrevit import script logger = script.get_logger() revisions = forms.select_revisions(button_name='Select Revision', multiple=True) logger.debug(revisions) if revisions: sheets = forms.select_sheets(button_name='Remove Revisions', include_placeholder=True) if sheets: with revit.Transaction('Remove Revision from Sheets'): updated_sheets = revit.update.update_sheet_revisions(revisions, sheets, state=False) if updated_sheets: print('SELECTED REVISION REMOVED FROM THESE SHEETS:') print('-' * 100) cloudedsheets = [] for s in sheets: if s in updated_sheets: revit.report.print_sheet(s) else: cloudedsheets.append(s) else:
@property def replace_name(self): return self.textbox2.Text def rename_elements(self, sender, args): self.Close() forms.check_modeldoc(revit.doc, exitscript=True) logger = script.get_logger() window = MyWindow() selected_sheets = forms.select_sheets(button_name='Select Sheets') if selected_sheets: # let's show the window (modal) window.ShowDialog() old_text = window.find_name new_text = window.replace_name with revit.Transaction("Rename Sheets"): for sheet in selected_sheets: try: if window.use_regex and window.use_ignorecase: pattern = re.compile(old_text, re.IGNORECASE) new_name = pattern.sub(new_text, sheet.Name) sheet.Name = new_name elif window.use_regex: pattern = re.compile(old_text) new_name = pattern.sub(new_text, sheet.Name)
"""Change template to nomination template then return back to previous template. Nomination template will override Visibility/Graphic that not controlled by previous template""" __author__='NguyenKhanhTien - [email protected]' from Autodesk.Revit.DB import ViewSheet, Transaction, View, TransactionGroup from pyrevit import revit, DB from pyrevit import forms doc = __revit__.ActiveUIDocument.Document viewsheet = forms.select_sheets(button_name='Select Sheet Set') selected_viewtemplates = forms.select_viewtemplates(doc=revit.doc) temp=selected_viewtemplates[0].Id save_tem = [] views = [] count=0 print("View from sheets:") for sheet in viewsheet: print (sheet.Title) print("------------------------------------------------------------------------------") print("Changing view template to: " + str(selected_viewtemplates[0].Name)) tg = TransactionGroup(doc, "Update Template") tg.Start() t=Transaction(doc,"Change Template") t.Start() for vs in viewsheet: for eid in vs.GetAllPlacedViews(): ev=doc.GetElement(eid) if str(ev.ViewType) != "Legend" and str(ev.ViewType) != "DraftingView":
def get_source_sheets(): sheet_elements = forms.select_sheets(button_name='Select TitleBlocks') if not sheet_elements: script.exit() return sheet_elements
"""Add selected view to selected sheets.""" from pyrevit import revit, DB from pyrevit import forms from pyrevit import script logger = script.get_logger() selected_views = forms.select_views(use_selection=True) if selected_views: logger.debug('Selected views: {}'.format(len(selected_views))) # get the destination sheets from user dest_sheets = forms.select_sheets(include_placeholder=False) if dest_sheets: logger.debug('Selected sheets: {}'.format(len(dest_sheets))) with revit.Transaction("Add Views to Sheets"): for selected_view in selected_views: for sheet in dest_sheets: logger.debug('Adding: %s', revit.query.get_name(selected_view)) try: DB.Viewport.Create(revit.doc, sheet.Id, selected_view.Id, DB.XYZ(0, 0, 0)) except Exception as place_err: logger.debug( 'Error placing view on sheet: {} -> {}'.format( selected_view.Id, sheet.Id)) else: forms.alert('No views selected.')
from pyrevit import forms def change_case(sheetlist, upper=True, verbose=False): with revit.Transaction('Rename Sheets to Upper'): for el in sheetlist: sheetnameparam = el.Parameter[DB.BuiltInParameter.SHEET_NAME] orig_name = sheetnameparam.AsString() new_name = orig_name.upper() if upper else orig_name.lower() if verbose: print('RENAMING:\t{0}\n' ' to:\t{1}\n'.format(orig_name, new_name)) sheetnameparam.Set(new_name) sel_sheets = forms.select_sheets(title='Select Sheets', use_selection=True) if sel_sheets: selected_option, switches = \ forms.CommandSwitchWindow.show( ['to UPPERCASE', 'to lowercase'], switches=['Show Report'], message='Select rename option:' ) if selected_option: change_case(sel_sheets, upper=True if selected_option == 'to UPPERCASE' else False, verbose=switches['Show Report'])
"""Set selected revisions on selected sheets.""" from pyrevit import revit, DB from pyrevit import forms revisions = forms.select_revisions(button_name='Select Revision', multiple=True) if revisions: sheets = forms.select_sheets(button_name='Set Revision', include_placeholder=False) if sheets: with revit.Transaction('Set Revision on Sheets'): updated_sheets = revit.update.update_sheet_revisions( revisions, sheets) if updated_sheets: print('SELECTED REVISION ADDED TO THESE SHEETS:') print('-' * 100) for s in updated_sheets: snum = s.Parameter[DB.BuiltInParameter.SHEET_NUMBER]\ .AsString().rjust(10) sname = s.Parameter[DB.BuiltInParameter.SHEET_NAME]\ .AsString().ljust(50) print('NUMBER: {0} NAME:{1}'.format(snum, sname))
from pyrevit import HOST_APP from pyrevit import revit, DB, UI from pyrevit import forms from pyrevit import script cursheet = revit.active_view forms.check_viewtype(cursheet, DB.ViewType.DrawingSheet, exitscript=True) dest_sheet = forms.select_sheets(title='Select Target Sheets', button_name='Select Sheets', multiple=False, include_placeholder=False, use_selection=True) selected_vports = [] if dest_sheet: sel = revit.pick_elements() for el in sel: selected_vports.append(el) if len(selected_vports) > 0: with revit.Transaction('Move Viewports'): for vp in selected_vports: if isinstance(vp, DB.Viewport): viewId = vp.ViewId vpCenter = vp.GetBoxCenter() vpTypeId = vp.GetTypeId() cursheet.DeleteViewport(vp) nvp = DB.Viewport.Create(revit.doc, dest_sheet.Id, viewId, vpCenter) nvp.ChangeTypeId(vpTypeId)
def main(): sourceSheet = forms.select_sheets(multiple=False) if sourceSheet is None: script.exit() #GETTING SOURCE VIEWPORTS COORDINATES sourceViewportIds = sourceSheet.GetAllViewports() sourceViewports = [] sourceViewportNums = [] sourcePts = [] for i in sourceViewportIds: sourceViewports.append(doc.GetElement(i)) sourcePts.append(doc.GetElement(i).GetBoxCenter()) sourceViewportNums.append( doc.GetElement(i).get_Parameter( BuiltInParameter.VIEWPORT_DETAIL_NUMBER).AsString()) locationDict = {} if len(sourceViewports) >= 1: locationDict = dict(zip(sourceViewportNums, sourcePts)) elif len(sourceViewports) < 1: forms.alert('No viewport on selected source sheet.') script.exit() if sourceViewports is None: script.exit() #GETTING VIEWPORTS ON THE SPECIFIED SHEET destSheets = forms.select_sheets() if destSheets is None: script.exit() allCategories = doc.Settings.Categories catIds = [] # Filter categories to just model categories + Matchlines and Scope Boxes for c in allCategories: if c.CategoryType == DB.CategoryType.Annotation: catIds.append(c.Id) elif c.CategoryType == DB.CategoryType.Model: if c.Name == 'Lighting Fixtures': catIds.append(c.Id) linkInstances = DB.FilteredElementCollector(doc)\ .OfClass(DB.RevitLinkInstance)\ .WhereElementIsNotElementType()\ .ToElements() linkInstanceIds = [] for link in linkInstances: linkInstanceIds.append(link.Id) #APPLYING SOURCE VIEW COORDINATES TO DESTINATION VIEWS with revit.Transaction('Align Multiple Viewports'): for svp in sourceViewports: view = doc.GetElement(svp.ViewId) hide_objects(view, catIds, linkInstanceIds) for sheet in destSheets: destViewports = [] temp = sheet.GetAllViewports() for i in temp: destViewports.append(doc.GetElement(i)) for dvp in destViewports: view = doc.GetElement(dvp.ViewId) hide_objects(view, catIds, linkInstanceIds) if len(destViewports) == len(sourceViewports): for vp in destViewports: viewNumber = vp.get_Parameter( BuiltInParameter.VIEWPORT_DETAIL_NUMBER).AsString() mappedLocation = locationDict.get(viewNumber, None) vp.SetBoxCenter(mappedLocation) unhide_objects(vp) else: forms.alert('Numbers of viewports don\'t match.') for svp in sourceViewports: unhide_objects(svp)
for exst_vp in exst_vps: if vport.ViewId == exst_vp.ViewId: exst_vp.SetBoxCenter(vport.GetBoxCenter()) exst_vp.ChangeTypeId(vport.GetTypeId()) return True return False selViewports = [] allSheetedSchedules = DB.FilteredElementCollector(revit.doc)\ .OfClass(DB.ScheduleSheetInstance)\ .ToElements() selected_sheets = forms.select_sheets(title='Select Target Sheets', button_name='Select Sheets') # get a list of viewports to be copied, updated if selected_sheets and len(selected_sheets) > 0: if int(__revit__.Application.VersionNumber) > 2014: cursheet = revit.uidoc.ActiveGraphicalView for v in selected_sheets: if cursheet.Id == v.Id: selected_sheets.remove(v) else: cursheet = selected_sheets[0] selected_sheets.remove(cursheet) revit.uidoc.ActiveView = cursheet selected_vps = revit.pick_elements()
with revit.Transaction('Pin all viewports'): for sheet in sheet_list: count = 0 alreadypinnedcount = 0 for vportid in sheet.GetAllViewports(): vport = revit.doc.GetElement(vportid) if not vport.Pinned: vport.Pinned = True count += 1 else: alreadypinnedcount += 1 print('Pinned {} viewports on sheet: {} - {}' '\n({} viewports were already pinned)'.format( count, sheet.SheetNumber, sheet.Name, alreadypinnedcount)) if __shiftclick__: if isinstance(revit.active_view, DB.ViewSheet): sel_sheets = [revit.active_view] else: forms.alert('Active view must be a sheet.') script.exit() else: sel_sheets = forms.select_sheets(title='Select Sheets', use_selection=True, include_placeholder=False) if sel_sheets: pin_viewports(sel_sheets)
#--- ELEMENT SELECTION ---------------------------------------- selec_ids = uidoc.Selection.GetElementIds() # New List containing only Sheets selec_el = [doc.GetElement(i) for i in selec_ids if doc.GetElement(i).GetType()==ViewSheet ] #---END ELEMENT SELECTION ------------------------------------- ### FEC VIEWsets ----------------------------------------------------- #FECviewsets = FilteredElementCollector(doc).OfClass(ViewSheetSet).ToElements() #create a dictionary from FECviewsets, key=viewsheetset-name : value=vss element #allviewss = {vss.Name: vss for vss in FECviewsets} # is a set, a dictionary is created if len(selec_el): #exist: 1 or 2, or 3 or ... , not 0 viewlist= selec_el else: viewlist = forms.select_sheets() # svs = FECviewsets[0] # Name Grundriss with 3 views #---SHEETVIEW: v0 ---------------------------------------- # viewlist = [i for i in svs.Views] if not viewlist: sys.exit() # ---FILENAME -------------------------------------------------------------------- # TIME --------- import datetime # considers Sommer and Winter Time m = datetime.datetime.now() date = "%d-%m-%y" # 05-06-18 leading 0 time = "%H.%M" #20.15 m.strftime(date) #stringformattime function
from pyrevit import HOST_APP from pyrevit import revit, DB, UI from pyrevit import forms from pyrevit import script __doc__ = 'Open the source sheet. Run this script and select destination '\ 'sheets. Select Viewports and push Finish button on the '\ 'properties bar. The selected views will be MOVED to '\ 'the destination sheets.' selViewports = [] dest_sheet = forms.select_sheets(title='Select Target Sheets', button_name='Select Sheets', multiple=False) if dest_sheet: cursheet = revit.activeview sel = revit.pick_elements() for el in sel: selViewports.append(el) if len(selViewports) > 0: with revit.Transaction('Move Viewports'): for vp in selViewports: if isinstance(vp, DB.Viewport): viewId = vp.ViewId vpCenter = vp.GetBoxCenter() vpTypeId = vp.GetTypeId() cursheet.DeleteViewport(vp)