Skip to content

Commit

Permalink
Implemented issue #313
Browse files Browse the repository at this point in the history
  • Loading branch information
eirannejad committed Mar 13, 2019
1 parent d47b9d4 commit 7c55328
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions pyrevitlib/pyrevit/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,7 @@ def select_revisions(title='Select Revision',
... [<Autodesk.Revit.DB.Revision object>,
... <Autodesk.Revit.DB.Revision object>]
"""
doc = doc or HOST_APP.doc
revisions = sorted(revit.query.get_revisions(doc=doc),
key=lambda x: x.SequenceNumber)

Expand Down Expand Up @@ -1537,6 +1538,7 @@ def select_views(title='Select Views',
... [<Autodesk.Revit.DB.View object>,
... <Autodesk.Revit.DB.View object>]
"""
doc = doc or HOST_APP.doc
all_graphviews = revit.query.get_all_views(doc=doc)

if filterfunc:
Expand All @@ -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()
... [<Autodesk.Revit.DB.View object>,
... <Autodesk.Revit.DB.View object>]
"""
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
Expand Down
38 changes: 37 additions & 1 deletion pyrevitlib/pyrevit/revit/db/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pyrevitlib/pyrevit/revit/db/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand Down

0 comments on commit 7c55328

Please sign in to comment.