Example #1
0
def remove_all_groups():
    """Remove (and Explode) All Groups"""
    def confirm_removal(group_type):
        return group_type \
            and group_type.Category.Name != 'Attached Detail Groups'

    group_types = list(
        DB.FilteredElementCollector(revit.doc).OfClass(
            framework.get_type(DB.GroupType)).ToElements())
    groups = list(
        DB.FilteredElementCollector(revit.doc).OfClass(
            framework.get_type(DB.Group)).ToElements())

    output = script.get_output()
    print_header('EXPLODING GROUPS')  # ungroup all groups

    with revit.TransactionGroup('Remove All Groups', assimilate=True):
        with revit.Transaction('Exploding All Groups'):
            for grp in groups:
                grp.UngroupMembers()

        # delete group types
        output.print_md('### {}'.format('REMOVING GROUPS'))
        remove_action('Remove All Groups',
                      'Group Type',
                      group_types,
                      validity_func=confirm_removal)
Example #2
0
    def _get_sheet_index_list(self):
        cl_schedules = DB.FilteredElementCollector(revit.doc)
        schedules = cl_schedules.OfClass(framework.get_type(DB.ViewSchedule))\
                                .WhereElementIsNotElementType()\
                                .ToElements()

        return [sched for sched in schedules if self._is_sheet_index(sched)]
Example #3
0
    def _make_fillpattern_element(rvt_fill_pat):
        # find existing filled pattern element matching name and pattern target
        existing_fillpatternelements = \
            DB.FilteredElementCollector(revit.doc)\
              .OfClass(framework.get_type(DB.FillPatternElement))
        fill_pat_element = None
        for exfpe in existing_fillpatternelements:
            exfp = exfpe.GetFillPattern()
            if rvt_fill_pat.Name == exfp.Name \
                    and rvt_fill_pat.Target == exfp.Target:
                fill_pat_element = exfpe

        if fill_pat_element:
            with revit.Transaction('Create Fill Pattern'):
                fill_pat_element.SetFillPattern(rvt_fill_pat)
                logger.debug('Updated FillPatternElement with id:{}'
                             .format(fill_pat_element.Id))
        else:
            with revit.Transaction('Create Fill Pattern'):
                fill_pat_element =\
                    DB.FillPatternElement.Create(revit.doc, rvt_fill_pat)
                logger.debug('Created FillPatternElement with id:{}'
                             .format(fill_pat_element.Id))

        logger.debug('Fill Pattern:{}'.format(fill_pat_element.Name))
        fp = fill_pat_element.GetFillPattern()
        logger.debug('Fill Grids Count: {}'.format(len(fp.GetFillGrids())))
        for idx, fg in enumerate(fp.GetFillGrids()):
            logger.debug('FillGrid #{} '
                         'Origin:{} Angle:{} Shift:{} Offset:{} Segments:{}'
                         .format(idx, fg.Origin,
                                 fg.Angle, fg.Shift,
                                 fg.Offset, fg.GetSegments()))
        return fill_pat_element
Example #4
0
    def _get_ordered_schedule_sheets(self):
        schedule_view = self.selected_schedule
        cl_sheets = DB.FilteredElementCollector(revit.doc, schedule_view.Id)
        sheets = cl_sheets.OfClass(framework.get_type(DB.ViewSheet))\
                          .WhereElementIsNotElementType()\
                          .ToElements()

        return self._order_sheets_by_schedule_data(schedule_view, sheets)
Example #5
0
def _make_filledregion(fillpattern_name, fillpattern_id):
    filledregion_types = DB.FilteredElementCollector(revit.doc)\
                           .OfClass(framework.get_type(DB.FilledRegionType))

    source_fr = filledregion_types.FirstElement()
    with revit.Transaction('Create Filled Region'):
        new_fr = source_fr.Duplicate(fillpattern_name)
        new_fr.FillPatternId = fillpattern_id
Example #6
0
def get_all_fillpattern_elements(fillpattern_target, doc=None):
    doc = doc or HOST_APP.doc
    existing_fp_elements = \
        DB.FilteredElementCollector(doc) \
          .OfClass(framework.get_type(DB.FillPatternElement))

    return [x for x in existing_fp_elements
            if x.GetFillPattern().Target == fillpattern_target]
Example #7
0
 def _find_linked_models(self):
     cl = DB.FilteredElementCollector(revit.doc)
     all_linked_models = \
         cl.OfClass(framework.get_type(DB.RevitLinkType)).ToElements()
     self.linked_models = [lm for lm in all_linked_models
                           if DB.RevitLinkType.IsLoaded(revit.doc, lm.Id)]
     self.linkedmodels_lb.ItemsSource = self.linked_models
     self.linkedmodels_lb.SelectedIndex = 0
Example #8
0
    def _print_combined_sheets_in_order(self):
        print_mgr = revit.doc.PrintManager
        print_mgr.PrintRange = DB.PrintRange.Select
        viewsheet_settings = print_mgr.ViewSheetSetting

        sheet_set = DB.ViewSet()

        # add non-printable char in front of sheet Numbers
        # to push revit to sort them per user
        original_sheetnums = []
        with revit.Transaction('Fix Sheet Numbers') as t:
            for idx, sheet in enumerate(self.sheets_lb.ItemsSource):
                sht = sheet.revit_sheet
                original_sheetnums.append(sht.SheetNumber)
                sht.SheetNumber = NPC * (idx + 1) + sht.SheetNumber
                sheet_set.Insert(sht)

        # Collect existing sheet sets
        cl = DB.FilteredElementCollector(revit.doc)
        viewsheetsets = cl.OfClass(framework.get_type(DB.ViewSheetSet))\
                          .WhereElementIsNotElementType()\
                          .ToElements()
        all_viewsheetsets = {vss.Name: vss for vss in viewsheetsets}

        sheetsetname = 'OrderedPrintSet'

        with revit.Transaction('Update Ordered Print Set') as t:
            # Delete existing matching sheet set
            if sheetsetname in all_viewsheetsets:
                viewsheet_settings.CurrentViewSheetSet = \
                    all_viewsheetsets[sheetsetname]
                viewsheet_settings.Delete()

            viewsheet_settings.CurrentViewSheetSet.Views = sheet_set
            viewsheet_settings.SaveAs(sheetsetname)

        print_mgr.PrintOrderReverse = self.reverse_print
        try:
            print_mgr.CombinedFile = True
        except Exception as e:
            forms.alert(str(e) + '\nSet printer correctly in Print settings.')
            script.exit()
        print_mgr.PrintToFile = True
        # [BB] Added savepath to join command
        print_mgr.PrintToFileName = op.join(savepath, 'Ordered Sheet Set.pdf')
        print_mgr.Apply()
        print_mgr.SubmitPrint()

        # now fix the sheet names
        with revit.Transaction('Restore Sheet Numbers') as t:
            for sheet, sheetnum in zip(self.sheets_lb.ItemsSource,
                                       original_sheetnums):
                sht = sheet.revit_sheet
                sht.SheetNumber = sheetnum
Example #9
0
    def _get_ordered_schedule_sheets(self):
        if self.selected_doc == self.selected_schedule.Document:
            sheets = DB.FilteredElementCollector(self.selected_doc,
                                                 self.selected_schedule.Id)\
                    .OfClass(framework.get_type(DB.ViewSheet))\
                    .WhereElementIsNotElementType()\
                    .ToElements()

            return self._order_sheets_by_schedule_data(self.selected_schedule,
                                                       sheets)
        return []
Example #10
0
def get_fillpattern_element(fillpattern_name, fillpattern_target, doc=None):
    doc = doc or HOST_APP.doc
    existing_fp_elements = \
        DB.FilteredElementCollector(doc) \
          .OfClass(framework.get_type(DB.FillPatternElement))

    for existing_fp_element in existing_fp_elements:
        fillpattern = existing_fp_element.GetFillPattern()
        if fillpattern_name == fillpattern.Name \
                and fillpattern_target == fillpattern.Target:
            return existing_fp_element
Example #11
0
 def _list_sheets(self):
     open_doc = self._get_linked_model_doc()
     if open_doc:
         cl_sheets = DB.FilteredElementCollector(open_doc)
         sheetsnotsorted = \
             cl_sheets.OfClass(framework.get_type(DB.ViewSheet))\
                      .WhereElementIsNotElementType()\
                      .ToElements()
         linked_sheets = \
             sorted(sheetsnotsorted, key=lambda x: x.SheetNumber)
         self.linkedsheets_lb.ItemsSource = linked_sheets
Example #12
0
def shake_filled_regions(view):
    fregions = DB.FilteredElementCollector(revit.doc)\
                 .OwnedByView(view.Id)\
                 .OfClass(framework.get_type(DB.FilledRegion))\
                 .WhereElementIsNotElementType()\
                 .ToElements()

    print('Shaking Filled Regions in: {}'.format(revit.query.get_name(view)))

    for i, fr in enumerate(fregions):
        with revit.Transaction('Shake Filled Region #{}'.format(i)):
            fr.Location.Move(DB.XYZ(0.01, 0, 0))
            fr.Location.Move(DB.XYZ(-0.01, 0, 0))
Example #13
0
def checkModel(doc, output):
    # heavily based on Views - Query view sheet placement in pyRevit

    scheduleviews = []
    all_sheeted_view_ids = []

    # Schedules need to be collected separately
    schedule_views = DB.FilteredElementCollector(revit.doc)\
                       .OfClass(framework.get_type(DB.ViewSchedule))\
                       .WhereElementIsNotElementType()\
                       .ToElements()

    for sv in schedule_views:
        scheduleviews.append(sv)


    # Now collecting all sheets and find all sheeted views
    sheets = DB.FilteredElementCollector(revit.doc)\
               .OfCategory(DB.BuiltInCategory.OST_Sheets)\
               .WhereElementIsNotElementType()\
               .ToElements()

    for sht in sheets:
        vp_ids = [revit.doc.GetElement(x).ViewId for x in sht.GetAllViewports()]
        all_sheeted_view_ids.extend(vp_ids)


    # Find all sheeted schedule views and add them to the list as well
    allSheetedSchedules = DB.FilteredElementCollector(revit.doc)\
                            .OfClass(DB.ScheduleSheetInstance)\
                            .ToElements()

    for ss in allSheetedSchedules:
        all_sheeted_view_ids.append(ss.ScheduleId)

    output.close_others()
    output.print_md('### SCHEDULES NOT ON ANY SHEETS')

    for v in scheduleviews:
        if v.Id in all_sheeted_view_ids:
            continue
        else:
            print('TYPE: {1}\t\tID: {2}\t\t{0}'.format(revit.query.get_name(v),
                                                       v.ViewType,
                                                       output.linkify(v.Id)))
Example #14
0
def createsheetset(revision_element):
    # get printed printmanager
    printmanager = revit.doc.PrintManager
    printmanager.PrintRange = DB.PrintRange.Select
    viewsheetsetting = printmanager.ViewSheetSetting

    # collect data
    sheetsnotsorted = DB.FilteredElementCollector(revit.doc)\
                        .OfCategory(DB.BuiltInCategory.OST_Sheets)\
                        .WhereElementIsNotElementType()\
                        .ToElements()

    sheets = sorted(sheetsnotsorted, key=lambda x: x.SheetNumber)
    viewsheetsets = DB.FilteredElementCollector(revit.doc)\
                      .OfClass(framework.get_type(DB.ViewSheetSet))\
                      .WhereElementIsNotElementType()\
                      .ToElements()

    allviewsheetsets = {vss.Name: vss for vss in viewsheetsets}
    revnum = revision_element.SequenceNumber
    if hasattr(revision_element, 'RevisionNumber'):
        revnum = revision_element.RevisionNumber
    sheetsetname = 'Rev {0}: {1}'.format(revnum, revision_element.Description)

    with revit.Transaction('Create Revision Sheet Set'):
        if sheetsetname in allviewsheetsets.keys():
            viewsheetsetting.CurrentViewSheetSet = \
                allviewsheetsets[sheetsetname]
            viewsheetsetting.Delete()

        # find revised sheets
        myviewset = DB.ViewSet()
        for sheet in sheets:
            revs = sheet.GetAllRevisionIds()
            revids = [x.IntegerValue for x in revs]
            if revision_element.Id.IntegerValue in revids:
                myviewset.Insert(sheet)

        # create new sheet set
        viewsheetsetting.CurrentViewSheetSet.Views = myviewset
        viewsheetsetting.SaveAs(sheetsetname)
Example #15
0
    def _print_combined_sheets_in_order(self):
        print_mgr = revit.doc.PrintManager
        print_mgr.PrintRange = DB.PrintRange.Select
        viewsheet_settings = print_mgr.ViewSheetSetting

        sheet_set = DB.ViewSet()

        # add non-printable char in front of sheet Numbers
        # to push revit to sort them per user
        original_sheetnums = []
        with revit.TransactionGroup('Print Sheets in Order') as tg:
            with revit.Transaction('Fix Sheet Numbers') as t:
                for idx, sheet in enumerate(self.sheets_lb.ItemsSource):
                    sht = sheet.revit_sheet
                    original_sheetnums.append(sht.SheetNumber)
                    sht.SheetNumber = NPC * (idx + 1) + sht.SheetNumber
                    sheet_set.Insert(sht)

            # Collect existing sheet sets
            cl = DB.FilteredElementCollector(revit.doc)
            viewsheetsets = cl.OfClass(framework.get_type(DB.ViewSheetSet))\
                              .WhereElementIsNotElementType()\
                              .ToElements()
            all_viewsheetsets = {vss.Name: vss for vss in viewsheetsets}

            sheetsetname = 'OrderedPrintSet'

            with revit.Transaction('Update Ordered Print Set') as t:
                # Delete existing matching sheet set
                if sheetsetname in all_viewsheetsets:
                    viewsheet_settings.CurrentViewSheetSet = \
                        all_viewsheetsets[sheetsetname]
                    viewsheet_settings.Delete()

                try:
                    viewsheet_settings.CurrentViewSheetSet.Views = sheet_set
                except Exception as viewset_err:
                    sheet_report = ''
                    for sheet in sheet_set:
                        sheet_report += '{} {}\n'.format(
                            sheet.SheetNumber if isinstance(
                                sheet, DB.ViewSheet) else '---', type(sheet))
                    logger.critical(
                        'Error setting sheet set on print mechanism. '
                        'These items are included in the viewset '
                        'object:\n{}'.format(sheet_report))
                    raise viewset_err
                viewsheet_settings.SaveAs(sheetsetname)

            print_mgr.PrintOrderReverse = self.reverse_print
            try:
                print_mgr.CombinedFile = True
            except Exception as e:
                forms.alert(
                    str(e) + '\nSet printer correctly in Print settings.')
                script.exit()
            print_mgr.PrintToFile = True
            print_mgr.PrintToFileName = op.join(r'C:', 'Ordered Sheet Set.pdf')
            print_mgr.Apply()
            print_mgr.SubmitPrint()

            # now fix the sheet names
            with revit.Transaction('Restore Sheet Numbers') as t:
                for sheet, sheetnum in zip(self.sheets_lb.ItemsSource,
                                           original_sheetnums):
                    sht = sheet.revit_sheet
                    sht.SheetNumber = sheetnum
Example #16
0
          .OfCategory(DB.BuiltInCategory.OST_Views)\
          .WhereElementIsNotElementType()\
          .ToElements()

for v in views:
    if not v.IsTemplate:
        if v.ViewType == DB.ViewType.DraftingView:
            dviews.append(v)
        elif v.ViewType == DB.ViewType.Legend:
            lviews.append(v)
        else:
            mviews.append(v)

# Schedules need to be collected separately
schedule_views = DB.FilteredElementCollector(revit.doc)\
                   .OfClass(framework.get_type(DB.ViewSchedule))\
                   .WhereElementIsNotElementType()\
                   .ToElements()

for sv in schedule_views:
    scheduleviews.append(sv)


# Now collecting all sheets and find all sheeted views
sheets = DB.FilteredElementCollector(revit.doc)\
           .OfCategory(DB.BuiltInCategory.OST_Sheets)\
           .WhereElementIsNotElementType()\
           .ToElements()

for sht in sheets:
    vp_ids = [revit.doc.GetElement(x).ViewId for x in sht.GetAllViewports()]
Example #17
0
    def get_rvt_obj(self):
        return self._rvt_type

    def find_linked_elements(self):
        with revit.DryTransaction("Search for linked elements",
                                  clear_after_rollback=True):
            linked_element_ids = revit.doc.Delete(self._rvt_type.Id)

        return linked_element_ids


# Collect viewport types
all_element_types = \
    DB.FilteredElementCollector(revit.doc)\
      .OfClass(framework.get_type(DB.ElementType))\
      .ToElements()

all_viewport_types = \
    [ViewPortType(x) for x in all_element_types if x.FamilyName == 'Viewport']

logger.debug('Viewport types: {}'.format(all_viewport_types))

# Ask user for viewport types to be purged
purge_vp_types = \
    forms.SelectFromList.show(sorted(all_viewport_types),
                              title='Select Types to be Converted',
                              multiselect=True)

if not purge_vp_types:
    sys.exit()
Example #18
0
    def _print_combined_sheets_in_order(self):
        # make sure we can access the print config
        print_mgr = self._get_printmanager()
        with revit.TransactionGroup('Print Sheets in Order'):
            if not print_mgr:
                return
            with revit.Transaction('Set Printer Settings'):
                print_mgr.PrintSetup.CurrentPrintSetting = \
                    self.selected_print_setting
                print_mgr.SelectNewPrintDriver(self.selected_printer)
                print_mgr.PrintRange = DB.PrintRange.Select
            # add non-printable char in front of sheet Numbers
            # to push revit to sort them per user
            sheet_set = DB.ViewSet()
            original_sheetnums = []
            with revit.Transaction('Fix Sheet Numbers'):
                for idx, sheet in enumerate(self.sheet_list):
                    rvtsheet = sheet.revit_sheet
                    original_sheetnums.append(rvtsheet.SheetNumber)
                    rvtsheet.SheetNumber = \
                        NPC * (idx + 1) + rvtsheet.SheetNumber
                    if sheet.printable:
                        sheet_set.Insert(rvtsheet)

            # Collect existing sheet sets
            cl = DB.FilteredElementCollector(revit.doc)
            viewsheetsets = cl.OfClass(framework.get_type(DB.ViewSheetSet))\
                              .WhereElementIsNotElementType()\
                              .ToElements()
            all_viewsheetsets = {vss.Name: vss for vss in viewsheetsets}

            sheetsetname = 'OrderedPrintSet'

            with revit.Transaction('Remove Previous Print Set'):
                # Delete existing matching sheet set
                if sheetsetname in all_viewsheetsets:
                    print_mgr.ViewSheetSetting.CurrentViewSheetSet = \
                        all_viewsheetsets[sheetsetname]
                    print_mgr.ViewSheetSetting.Delete()

            with revit.Transaction('Update Ordered Print Set'):
                try:
                    viewsheet_settings = print_mgr.ViewSheetSetting
                    viewsheet_settings.CurrentViewSheetSet.Views = \
                        sheet_set
                    viewsheet_settings.SaveAs(sheetsetname)
                except Exception as viewset_err:
                    sheet_report = ''
                    for sheet in sheet_set:
                        sheet_report += '{} {}\n'.format(
                            sheet.SheetNumber if isinstance(
                                sheet, DB.ViewSheet) else '---', type(sheet))
                    logger.critical(
                        'Error setting sheet set on print mechanism. '
                        'These items are included in the viewset '
                        'object:\n%s', sheet_report)
                    raise viewset_err

            # set print job configurations
            print_mgr.PrintOrderReverse = self.reverse_print
            try:
                print_mgr.CombinedFile = True
            except Exception as e:
                forms.alert(
                    str(e) + '\nSet printer correctly in Print settings.')
                script.exit()
            print_mgr.PrintToFile = True
            print_mgr.PrintToFileName = \
                op.join(r'C:\\', 'Ordered Sheet Set.pdf')
            print_mgr.Apply()
            print_mgr.SubmitPrint()

            # now fix the sheet names
            with revit.Transaction('Restore Sheet Numbers'):
                for sheet, sheetnum in zip(self.sheet_list,
                                           original_sheetnums):
                    rvtsheet = sheet.revit_sheet
                    rvtsheet.SheetNumber = sheetnum
Example #19
0
from pyrevit import framework
from pyrevit import revit, DB


__doc__ = 'List all detail groups that include a text element inside them. '\
          'This is helpful for spell checking.'

grps = list(
    DB.FilteredElementCollector(revit.doc).OfClass(framework.get_type(
        DB.Group)).ToElements())

grpTypes = set()

for g in grps:
    mems = g.GetMemberIds()
    for el in mems:
        mem = revit.doc.GetElement(el)
        if isinstance(mem, DB.TextNote):
            grpTypes.add(g.GroupType.Id)

for gtId in grpTypes:
    print(revit.query.get_name(revit.doc.GetElement(gtId)))
Example #20
0
    # add non-printable char in front of sheet Numbers
    # to push revit to sort them per user
sheet_set = DB.ViewSet()
original_sheetnums = []
with DB.Transaction(doc,'Add Sheets') as tg:
    tg.Start()
    for rvtsheet in select_sheets:
        try:
            sheet_set.Insert(rvtsheet)
        except Exception as e:
            forms.alert(str(e),exitscript=True)
    tg.Commit()

# Collect existing sheet sets
cl = DB.FilteredElementCollector(revit.doc)
viewsheetsets = cl.OfClass(framework.get_type(DB.ViewSheetSet))\
                    .WhereElementIsNotElementType()\
                    .ToElements()

all_viewsheetsets = {vss.Name: vss for vss in viewsheetsets}
with revit.Transaction('Remove Previous Print Set') as t:
    # Delete existing matching sheet set
    if sheetsetname in all_viewsheetsets:
        print_mgr.ViewSheetSetting.CurrentViewSheetSet = \
            all_viewsheetsets[sheetsetname]
        print_mgr.ViewSheetSetting.Delete()

with revit.Transaction('Create Print Set') as t:
    try:
        viewsheet_settings = print_mgr.ViewSheetSetting
        viewsheet_settings.CurrentViewSheetSet.Views = sheet_set
Example #21
0
        # Ask for a print set name and check if need to be replaced
        sheetsetname = None
        while not sheetsetname\
                or (sheetsetname in print_sets_names_existing
                and not forms.alert("Replace existing Print Set?",
                                yes=True, no=True)):
            sheetsetname = forms.ask_for_string(
                default=print_sets_names_existing[-1]\
                    if print_sets_names_existing else 'ViewPrintSet',
                prompt="Give new Print Set a Name:")
            if not sheetsetname:
                script.exit()

        # Collect existing sheet sets
        viewsheetsets = DB.FilteredElementCollector(revit.doc)\
                          .OfClass(framework.get_type(DB.ViewSheetSet))\
                          .WhereElementIsNotElementType()\
                          .ToElements()

        allviewsheetsets = {vss.Name: vss for vss in viewsheetsets}

        with revit.Transaction('Created Print Set'):
            # Delete existing matching sheet set
            if sheetsetname in allviewsheetsets.keys():
                viewsheetsetting.CurrentViewSheetSet = \
                    allviewsheetsets[sheetsetname]
                viewsheetsetting.Delete()

            # Create new sheet set
            viewsheetsetting.CurrentViewSheetSet.Views = myviewset
            viewsheetsetting.SaveAs(sheetsetname)
Example #22
0
"""List all groups that includethe selected group element as a nested group."""

from pyrevit import framework
from pyrevit import revit, DB


selection = revit.get_selection()


grps = list(DB.FilteredElementCollector(revit.doc)
              .OfClass(framework.get_type(DB.Group))
              .ToElements())

grpTypes = set()


if len(selection) > 0:
    for el in selection:
        if isinstance(el, DB.Group):
            selectedgtid = el.GroupType.Id
            for g in grps:
                mems = g.GetMemberIds()
                for memid in mems:
                    mem = revit.doc.GetElement(memid)
                    if isinstance(mem, DB.Group):
                        memgtid = mem.GroupType.Id
                        if memgtid == selectedgtid:
                            grpTypes.add(g.GroupType.Id)

            for gtId in grpTypes:
                print(revit.query.get_name(revit.doc.GetElement(gtId)))