diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Revision.pulldown/Copy Revisions to Open Documents.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Revision.pulldown/Copy Revisions to Open Documents.pushbutton/script.py index 9b1dbd075..5f202f15c 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Revision.pulldown/Copy Revisions to Open Documents.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/Revision.pulldown/Copy Revisions to Open Documents.pushbutton/script.py @@ -15,6 +15,8 @@ if dest_docs: for ddoc in dest_docs: with revit.Transaction('Copy Revisions', doc=ddoc): - revit.create.copy_revisions(src_doc=revit.doc, - dest_doc=ddoc, - revisions=selected_revisions) + revit.create.copy_revisions( + selected_revisions, + src_doc=revit.doc, + dest_doc=ddoc + ) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/Copy View Templates to Open Documents.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/Copy View Templates to Open Documents.pushbutton/script.py new file mode 100644 index 000000000..0e2509585 --- /dev/null +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/Copy View Templates to Open Documents.pushbutton/script.py @@ -0,0 +1,17 @@ +"""Copy selected view templates to other open models.""" +#pylint: disable=import-error,invalid-name +from pyrevit import revit +from pyrevit import forms + + +selected_viewtemplates = forms.select_viewtemplates(doc=revit.doc) +if selected_viewtemplates: + dest_docs = forms.select_open_docs(title='Select Destination Documents') + if dest_docs: + for ddoc in dest_docs: + with revit.Transaction('Copy View Templates', doc=ddoc): + revit.create.copy_viewtemplates( + selected_viewtemplates, + src_doc=revit.doc, + dest_doc=ddoc + ) diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/_layout b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/_layout index 73fb4bd11..9de468458 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/_layout +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Drawing Set.panel/views.stack3/Views.pulldown/_layout @@ -9,6 +9,7 @@ Rename Selected Views Duplicate Selected Views Create Print Set From Selected Views Find Used View Templates Filters +Copy View Templates to Open Documents Toggle All Grid Bubbles in Current View Match Title on Sheet in Open Docs Add Views to Sheets diff --git a/pyrevitlib/pyrevit/forms/__init__.py b/pyrevitlib/pyrevit/forms/__init__.py index 0103dd9f3..5b60bc84f 100644 --- a/pyrevitlib/pyrevit/forms/__init__.py +++ b/pyrevitlib/pyrevit/forms/__init__.py @@ -1421,6 +1421,7 @@ def select_revisions(title='Select Revision', ... [, ... ] """ + doc = doc or HOST_APP.doc revisions = sorted(revit.query.get_revisions(doc=doc), key=lambda x: x.SequenceNumber) @@ -1537,6 +1538,7 @@ def select_views(title='Select Views', ... [, ... ] """ + doc = doc or HOST_APP.doc all_graphviews = revit.query.get_all_views(doc=doc) if filterfunc: @@ -1555,6 +1557,53 @@ def select_views(title='Select Views', return selected_views +def select_viewtemplates(title='Select View Templates', + button_name='Select', + width=DEFAULT_INPUTWINDOW_WIDTH, + multiple=True, + filterfunc=None, + doc=None): + """Standard form for selecting view templates. + + Args: + title (str, optional): list window title + button_name (str, optional): list window button caption + width (int, optional): width of list window + multiselect (bool, optional): + allow multi-selection (uses check boxes). defaults to True + filterfunc (function): + filter function to be applied to context items. + doc (DB.Document, optional): + source document for views; defaults to active document + + Returns: + list[DB.View]: list of selected view templates + + Example: + >>> from pyrevit import forms + >>> forms.select_viewtemplates() + ... [, + ... ] + """ + doc = doc or HOST_APP.doc + all_viewtemplates = revit.query.get_all_view_templates(doc=doc) + + if filterfunc: + all_viewtemplates = filter(filterfunc, all_viewtemplates) + + selected_viewtemplates = SelectFromList.show( + sorted([ViewOption(x) for x in all_viewtemplates], + key=lambda x: x.name), + title=title, + button_name=button_name, + width=width, + multiselect=multiple, + checked_only=True + ) + + return selected_viewtemplates + + def select_open_docs(title='Select Open Documents', button_name='OK', width=DEFAULT_INPUTWINDOW_WIDTH, #pylint: disable=W0613 diff --git a/pyrevitlib/pyrevit/revit/db/create.py b/pyrevitlib/pyrevit/revit/db/create.py index b129dbaac..4317e05b0 100644 --- a/pyrevitlib/pyrevit/revit/db/create.py +++ b/pyrevitlib/pyrevit/revit/db/create.py @@ -29,6 +29,14 @@ def OnSharedFamilyFound(self, return True +class CopyUseDestination(DB.IDuplicateTypeNamesHandler): + """Handle copy and paste errors.""" + + def OnDuplicateTypeNamesFound(self, args): + """Use destination model types if duplicate.""" + return DB.DuplicateTypeAction.UseDestinationTypes + + def create_param_from_definition(param_def, category_list, builtin_param_group, @@ -147,7 +155,21 @@ def create_revision(description=None, by=None, to=None, date=None, return new_rev -def copy_revisions(src_doc, dest_doc, revisions=None): +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_revisions(revisions, src_doc, dest_doc): if revisions is None: all_src_revs = query.get_revisions(doc=src_doc) else: @@ -169,6 +191,20 @@ def copy_revisions(src_doc, dest_doc, revisions=None): doc=dest_doc) +def copy_all_revisions(src_doc, dest_doc): + copy_revisions(None, src_doc=src_doc, dest_doc=dest_doc) + + +def copy_viewtemplates(viewtemplates, src_doc, dest_doc): + if viewtemplates is None: + all_viewtemplates = query.get_all_view_templates(doc=src_doc) + else: + all_viewtemplates = viewtemplates + + vtemp_ids = [x.Id for x in all_viewtemplates] + copy_elements(vtemp_ids, src_doc=src_doc, dest_doc=dest_doc) + + def create_sheet(sheet_num, sheet_name, titleblock_id=DB.ElementId.InvalidElementId, doc=None): doc = doc or HOST_APP.doc diff --git a/pyrevitlib/pyrevit/revit/db/query.py b/pyrevitlib/pyrevit/revit/db/query.py index 13429efa6..951cf55f5 100644 --- a/pyrevitlib/pyrevit/revit/db/query.py +++ b/pyrevitlib/pyrevit/revit/db/query.py @@ -522,7 +522,9 @@ def get_all_views(doc=None, view_types=None, include_nongraphical=False): def get_all_view_templates(doc=None, view_types=None): - return [x for x in get_all_views(doc=doc, view_types=view_types) + return [x for x in get_all_views(doc=doc, + view_types=view_types, + include_nongraphical=True) if x.IsTemplate]