def copy_sheet_guides(activedoc, source_sheet, dest_doc, dest_sheet): # sheet guide source_sheet_guide_param = \ source_sheet.Parameter[DB.BuiltInParameter.SHEET_GUIDE_GRID] source_sheet_guide_element = \ activedoc.GetElement(source_sheet_guide_param.AsElementId()) if source_sheet_guide_element: if not find_guide(source_sheet_guide_element.Name, dest_doc): # copy guides to dest_doc cp_options = DB.CopyPasteOptions() cp_options.SetDuplicateTypeNamesHandler(CopyUseDestination()) with revit.Transaction('Copy Sheet Guide', doc=dest_doc): DB.ElementTransformUtils.CopyElements( activedoc, List[DB.ElementId]([source_sheet_guide_element.Id]), dest_doc, None, cp_options) dest_guide = find_guide(source_sheet_guide_element.Name, dest_doc) if dest_guide: # set the guide with revit.Transaction('Set Sheet Guide', doc=dest_doc): dest_sheet_guide_param = \ dest_sheet.Parameter[DB.BuiltInParameter.SHEET_GUIDE_GRID] dest_sheet_guide_param.Set(dest_guide.Id) else: logger.error( 'Error copying and setting sheet guide for sheet {}'.format( source_sheet.Name))
def copy_view_contents(activedoc, source_view, dest_doc, dest_view, clear_contents=False): logger.debug('Copying view contents: {} : {}'.format( source_view.Name, source_view.ViewType)) elements_ids = get_view_contents(activedoc, source_view) if clear_contents: if not clear_view_contents(dest_doc, dest_view): return False cp_options = DB.CopyPasteOptions() cp_options.SetDuplicateTypeNamesHandler(CopyUseDestination()) if elements_ids: with revit.Transaction('Copy View Contents', doc=dest_doc, swallow_errors=True): DB.ElementTransformUtils.CopyElements( source_view, List[DB.ElementId](elements_ids), dest_view, None, cp_options) return True
def copy_elements(element_ids, src_doc, dest_doc): cp_options = DB.CopyPasteOptions() cp_options.SetDuplicateTypeNamesHandler(CopyUseDestination()) if element_ids: DB.ElementTransformUtils.CopyElements( src_doc, framework.List[DB.ElementId](element_ids), dest_doc, None, cp_options) return True
def copy_paste_elements_btwn_views(source_view, destination_view): elements_to_copy = get_copyable_elements(source_view) if len(elements_to_copy) >= 1: # copying and pasting elements trans_name = 'Copy and Paste elements' try: with DB.Transaction(doc, trans_name) as t: t.Start() failure_ops = t.GetFailureHandlingOptions() failure_ops.SetFailuresPreprocessor( ViewConverterFailurePreProcessor( trans_name, revit.query.get_name(source_view))) # failure_ops.SetForcedModalHandling(False) t.SetFailureHandlingOptions(failure_ops) options = DB.CopyPasteOptions() options.SetDuplicateTypeNamesHandler(CopyUseDestination()) copied_element = \ DB.ElementTransformUtils.CopyElements( source_view, framework.List[DB.ElementId](elements_to_copy), destination_view, None, options ) # matching element graphics overrides and view properties if len(copied_element) != len(elements_to_copy): logger.warning( 'Some elements were not copied from view: {}'.format( revit.query.get_name(source_view))) for dest, src in zip(copied_element, elements_to_copy): destination_view.SetElementOverrides( dest, source_view.GetElementOverrides(src)) t.Commit() return len(copied_element) except Exception as err: logger.error( 'Error occured while copying elements from {} | {}'.format( revit.query.get_name(source_view), err)) return 0 else: print('No copyable elements where found.')
def copy_viewport_types(activedoc, vport_type, vport_typename, dest_doc, newvport): dest_vport_typenames = [DBElement.Name.GetValue(dest_doc.GetElement(x)) for x in newvport.GetValidTypes()] cp_options = DB.CopyPasteOptions() cp_options.SetDuplicateTypeNamesHandler(CopyUseDestination()) if vport_typename not in dest_vport_typenames: with revit.Transaction('Copy Viewport Types', doc=dest_doc, swallow_errors=True): DB.ElementTransformUtils.CopyElements( activedoc, List[DB.ElementId]([vport_type.Id]), dest_doc, None, cp_options, )
if isinstance(el, DB.Element) \ and el.Category \ and el.Category.Name != 'Legend Components': elements_to_copy.append(el.Id) else: logger.debug('Skipping element: %s', el.Id) if not elements_to_copy: logger.debug('Skipping empty view: %s', src_legend.ViewName) continue # start creating views and copying elements with revit.Transaction('Imported Legends as Drafting', doc=dest_doc): dest_view = DB.ViewDrafting.Create(dest_doc, drafting_view_type.Id) options = DB.CopyPasteOptions() options.SetDuplicateTypeNamesHandler(CopyUseDestination()) copied_elements = \ DB.ElementTransformUtils.CopyElements( src_legend, List[DB.ElementId](elements_to_copy), dest_view, None, options) # matching element graphics overrides and view properties for dest, src in zip(copied_elements, elements_to_copy): dest_view.SetElementOverrides( dest, src_legend.GetElementOverrides(src) )
if vN in v: dupViewTemplates.append(vT) # Views with view templates def checkViewT(viewsList): viewsWVT = {} for v in viewsList: if v.ViewTemplateId != DB.ElementId.InvalidElementId: viewsWVT.setdefault(v.ViewTemplateId.ToString(), []).append(v) return viewsWVT # Transform object transIdent = DB.Transform.Identity copyPasteOpt = DB.CopyPasteOptions() # Create single transaction and start it t = DB.Transaction(doc, "Copy View Templates") t.Start() # Check for all views that has a view template vTIds = [] viewsWVT = checkViewT(docViewsCollector) viewsFail = [] viewsSuccess = [] for vT in vTemplates: vTId = List[DB.ElementId]() for pro in selProject: if pro.Title in vT: vTId.Add(viewTemplates[vT].Id)