Ejemplo n.º 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(
        FilteredElementCollector(doc).OfClass(
            clr.GetClrType(GroupType)).ToElements())
    groups = list(
        FilteredElementCollector(doc).OfClass(
            clr.GetClrType(Group)).ToElements())

    print_header('EXPLODING GROUPS')  # ungroup all groups

    with ActionGroup('Remove All Groups', assimilate=True):
        with Action('Exploding All Groups'):
            for grp in groups:
                grp.UngroupMembers()

        # delete group types
        this_script.output.print_md('### {}'.format('REMOVING GROUPS'))
        remove_action('Remove All Groups',
                      'Group Type',
                      group_types,
                      validity_func=confirm_removal)
Ejemplo n.º 2
0
def remove_action(action_title,
                  action_cat,
                  elements_to_remove,
                  validity_func=None):
    def remove_element(rem_el):
        if rem_el:
            try:
                log_debug('Removing element:{} id:{}'.format(
                    rem_el, rem_el.Id))
                doc.Delete(rem_el.Id)
                return True
            except Exception as e:
                if hasattr(rem_el, 'Id'):
                    log_error(el_type=action_cat,
                              el_id=rem_el.Id,
                              delete_err=e)
                else:
                    log_error(el_type=action_cat, delete_err=e)
        else:
            log_debug(
                'Element does not have value. It might have been already removed by other actions.'
            )

        return False

    with Action(action_title):
        for element in elements_to_remove:
            if validity_func:
                if validity_func(element):
                    remove_element(element)
            else:
                remove_element(element)
Ejemplo n.º 3
0
def remove_action(action_title,
                  action_cat,
                  elements_to_remove,
                  validity_func=None):
    def remove_element(rem_el):
        if rem_el:
            try:
                log_debug('Removing element:{} id:{}'.format(
                    rem_el, rem_el.Id))
                doc.Delete(rem_el.Id)
                return True
            except Exception as e:
                if hasattr(rem_el, 'Id'):
                    log_error(el_type=action_cat,
                              el_id=rem_el.Id,
                              delete_err=e)
                else:
                    log_error(el_type=action_cat, delete_err=e)
        else:
            log_debug(
                'Element does not have value. It might have been already removed by other actions.'
            )

        return False

    rem_count = len(elements_to_remove)
    this_script.output.reset_progress()
    with Action(action_title):
        for idx, element in enumerate(elements_to_remove):
            this_script.output.update_progress(idx + 1, rem_count)
            if validity_func:
                try:
                    if validity_func(element):
                        remove_element(element)
                except Exception as e:
                    log_debug('Validity func failed. | {}'.format(e))
                    continue
            else:
                remove_element(element)

    print('Completed...\n')
Ejemplo n.º 4
0
if selection.is_empty:
    if isinstance(curview, ViewSheet):
        sheetlist.append(curview)
else:
    for sel_view in selection:
        if isinstance(sel_view, ViewSheet):
            sheetlist.append(sel_view)

if not sheetlist:
    TaskDialog.Show(
        'pyrevit',
        'You must have at least one sheet selected or active view must be a sheet.'
    )
    sys.exit()

with Action('Pin all viewports'):
    for sheet in sheetlist:
        count = 0
        alreadypinnedcount = 0
        for vportid in sheet.GetAllViewports():
            vport = 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))
Ejemplo n.º 5
0
            if len(list(el.GetMaterialIds(True))) > 0:
                set.append(elId)
            elif isinstance(el, Wall) and el.IsStackedWall:
                memberWalls = el.GetStackedWallMemberIds()
                for mwid in memberWalls:
                    mw = doc.GetElement(mwid)
                    if len(list(mw.GetMaterialIds(True))) > 0:
                        set.append(elId)
        element_to_isolate = List[ElementId](set)

    elif selected_switch == 'Model Elements':
        elements = FilteredElementCollector(
            doc, curview.Id).WhereElementIsNotElementType().ToElementIds()

        element_to_isolate = []
        for elid in elements:
            el = doc.GetElement(elid)
            if not el.ViewSpecific:  #and not isinstance(el, Dimension):
                element_to_isolate.append(elid)

        element_to_isolate = List[ElementId](element_to_isolate)

    else:
        element_to_isolate = FilteredElementCollector(doc, curview.Id) \
                             .OfCategory(element_cats[selected_switch]) \
                             .WhereElementIsNotElementType().ToElementIds()

    # now that list of elements is ready, let's isolate them in the active view
    with Action('Isolate {}'.format(selected_switch)):
        curview.IsolateElementsTemporary(element_to_isolate)
Ejemplo n.º 6
0
"""Converts the select text note element into lowercase text."""

from revitutils import doc, selection, Action

with Action('to Lower'):
    for el in selection.elements:
        el.Text = el.Text.lower()
Ejemplo n.º 7
0
# noinspection PyUnresolvedReferences
from Autodesk.Revit.DB import FilteredElementCollector as Fec
# noinspection PyUnresolvedReferences
from Autodesk.Revit.DB import BuiltInCategory, LinkElementId, UV, XYZ, ViewSection, ViewPlan

views = Fec(doc).OfCategory(
    BuiltInCategory.OST_Views).WhereElementIsNotElementType().ToElements()
rooms = Fec(doc).OfCategory(
    BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements()


def GetElementCenter(el, v):
    cen = el.Location.Point
    z = (el.UpperLimit.Elevation + el.LimitOffset) / 2
    cen = cen.Add(XYZ(0, 0, z))
    return cen


with Action('Tag All Rooms in All Views'):
    for v in views:
        for el in rooms:
            room_center = GetElementCenter(el, v)
            if type(v) in [ViewSection, ViewPlan]:
                logger.debug('Working on view: %s' % v.ViewName)
                roomtag = doc.Create.NewRoomTag(
                    LinkElementId(el.Id), UV(room_center.X, room_center.Y),
                    v.Id)
                if isinstance(v, ViewSection):
                    roomtag.Location.Move(XYZ(0, 0, room_center.Z))
Ejemplo n.º 8
0
purge_dict = {}
for purge_vp_type in purge_vp_types:
    logger.info('Finding all viewports of type: {}'.format(purge_vp_type.name))
    logger.debug('Purging: {}'.format(repr(purge_vp_type)))
    linked_elements = purge_vp_type.find_linked_elements()
    logger.debug('{} elements are linked to this viewport type.'.format(
        len(linked_elements)))
    purge_dict[purge_vp_type.name] = linked_elements

# Perform cleanup ------------------------------------------------------------------------------------------------------
with ActionGroup('Fixed Unpurgable Viewport Types'):
    # Correct all existing viewports that use the viewport types to be purged
    # Collect viewports and find the ones that use the purging viewport types
    all_viewports = Fec(doc).OfClass(clr.GetClrType(Viewport)).ToElements()
    purge_vp_ids = [x.get_rvt_obj().Id for x in purge_vp_types]
    with Action('Correct Viewport Types'):
        for vp in all_viewports:
            if vp.GetTypeId() in purge_vp_ids:
                try:
                    # change their type to the destination type
                    logger.debug(
                        'Changing viewport type for viewport with id: {}'.
                        format(vp.Id))
                    vp.ChangeTypeId(dest_vp_typeid)
                except Exception as change_err:
                    logger.debug(
                        'Can not change type for viewport with id: {} | {}'.
                        format(vp.Id, change_err))

    # Correct all hidden viewport elements that use the viewport types to be purged
    with Action('Correct Hidden Viewport Types'):
Ejemplo n.º 9
0
"""Capitalizes the first letter of the selected text note."""

from revitutils import doc, selection, Action


def get_first_alpha_index(src_string):
    for idx, char in enumerate(src_string):
        if char.isalpha():
            return idx

    return None


with Action('to Sentence case'):
    for el in selection.elements:
        new_sentence = ''
        for word in unicode(el.Text).split():
            idx = get_first_alpha_index(word)
            if idx is not None:
                new_sentence += ' ' + word[:idx].lower() + word[idx].upper(
                ) + word[idx + 1:].lower()

        el.Text = new_sentence
Ejemplo n.º 10
0
"""Toggles visibility of imported categories on current view"""

# from rpw import activeview, Action
from revitutils import curview, Action
activeview = curview

with Action('Toggle Imported'):
    activeview.AreImportCategoriesHidden = \
        not activeview.AreImportCategoriesHidden
Ejemplo n.º 11
0
"""Converts the select text note element into UPPERCASE text."""

from revitutils import doc, selection, Action

with Action('to Upper'):
    for el in selection.elements:
        el.Text = el.Text.upper()