Ejemplo n.º 1
0
    def find_linked_elements(self):
        t = Transaction(doc, "Search for linked elements")
        t.Start()
        linked_element_ids = doc.Delete(self._rvt_type.Id)
        t.RollBack()

        return linked_element_ids
Ejemplo n.º 2
0
def main():
    cl_sheets = FilteredElementCollector(doc)
    levels_all = cl_sheets.OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType().ToElements()

    options = []
    for l in levels_all:
        cb = CheckBoxLevel(l)
        options.append(cb)

    if len(options) == 0:
        print("Levels wasn't found")
        return
    selected1 = SelectFromCheckBoxes.show(options, title='Select levels to delete', width=300,
                                               button_name='OK')

    if not selected1:
        print("Nothing selected")
        return

    selected_levels1 = [c.level for c in selected1 if c.state == True]
    options = [c for c in selected1 if c.state != True]
    # print(selected_levels1)
    selected2 = SelectFromList.show(options, title='Select target level', width=300,
                                          button_name='OK')

    if len(options) == 0:
        print("You selected all levels")
        return

    if not selected2:
        print("Nothing selected")
        return
    print(selected2)
    selected_levels2 = [c.level for c in selected2]
    target_level = selected_levels2[0]
    errors = set()
    changed = set()
    for l in selected_levels1:
        objects_to_change = []

        t = Transaction(doc, "Check level " + l.Name)
        t.Start()
        elements = doc.Delete(l.Id)
        t.RollBack()

        errors_, changed_ = LevelChangePreselected(elements, target_level.Id)

        errors = errors.union(set(errors_))
        changed = changed.union(set(changed_))

    if errors:
        print("Errors")
        print( ",".join(list(errors)))

    if changed:
        print("\nChanged")
        print( ",".join(list(changed)))
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
"""Remove all materials that their names starts with 'Render'."""

from revitutils import doc, selection
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, Transaction
from Autodesk.Revit.UI import TaskDialog

with Transaction(doc, 'Remove All Materials') as t:
    t.Start()
    cl = FilteredElementCollector(doc)
    materials = cl.OfCategory(BuiltInCategory.OST_Materials
                              ).WhereElementIsNotElementType().ToElements()

    count = 0

    for m in materials:
        if m.Name.startswith('Render'):
            try:
                doc.Delete(m.Id)
                count += 1
            except Exception as e:
                logger.error('Material', m.Id, e)
                continue
    t.Commit()

    TaskDialog.Show('pyRevit', '{} materials removed.'.format(count))
Ejemplo n.º 5
0
for v in views:
    try:
        filters = v.GetFilters()
        for flid in filters:
            usedFiltersSet.add(flid.IntegerValue)
    except:
        continue

unusedFilters = allFilters - usedFiltersSet

if unusedFilters:
    print('{} Filters have not been used and will be purged.'.format(
        len(unusedFilters)))

    t = Transaction(doc, 'Purge Unused Filters')
    t.Start()

    for flid in unusedFilters:
        fl = doc.GetElement(ElementId(flid))
        print('Purging Filter: {0}\t{1}'.format(fl.Id, fl.Name))
        try:
            doc.Delete(ElementId(flid))
        except Exception as del_err:
            logger.error('Error purging filter: {} | {}'.format(
                fl.Name, del_err))

    t.Commit()
else:
    print('All filters are in use. No purging in necessary.')
Ejemplo n.º 6
0
See this link for a copy of the GNU General Public License protecting this package.
https://github.com/CyrilWaechter/pypevitmep/blob/master/LICENSE
"""

from revitutils import doc

# noinspection PyUnresolvedReferences
from Autodesk.Revit.DB import Transaction, FilteredElementCollector, ParameterElement

__doc__ = "Delete project parameters including hidden ones"
__title__ = "Project\nParameter\ndelete"
__author__ = "Cyril Waechter"

#Retrieve all parameters in the document
params = FilteredElementCollector(doc).OfClass(ParameterElement)
filteredparams = []

#Store parameters which has a name starting with "magi" or "MC"
for param in params:
    if param.Name.startswith(("magi", "MC")):  #startswith method accept tuple
        filteredparams.append(param)
        print param.Name

#Delete all parameters in the list
t = Transaction(doc, "Delete parameters")
t.Start()
for param in filteredparams:
    doc.Delete(param.Id)
t.Commit()
Ejemplo n.º 7
0
if not op.exists(fam_doc_path):
    TaskDialog.Show(
        'pyRevit',
        'Can not file original family file at\n{}'.format(fam_doc_path))
    logger.debug(
        'Can not file original family file at {}'.format(fam_doc_path))
    this_script.exit()
else:
    logger.debug('Loading family from: {}'.format(fam_doc_path))

# fake load the family so we can get the symbols -----------------------------------------------------------------------
symbol_list = set()
with Transaction(doc, 'Fake load') as t:
    t.Start()
    # remove existing family so we can load the original
    doc.Delete(fam_symbol.Id)
    # now load the original
    ret_ref = clr.Reference[Family]()
    doc.LoadFamily(fam_doc_path, ret_ref)
    loaded_fam = ret_ref.Value
    # get the symbols from the original
    for sym_id in loaded_fam.GetFamilySymbolIds():
        fam_sym = doc.GetElement(sym_id)
        fam_sym_name = Element.Name.GetValue(fam_sym)
        sortable_sym = SmartSortableFamilyType(fam_sym_name)
        logger.debug('Importable Type: {}'.format(sortable_sym))
        symbol_list.add(sortable_sym)
    # okay. we have all the symbols. now rollback all the changes
    t.RollBack()

# ask user for required symbol and load into current document ----------------------------------------------------------
Ejemplo n.º 8
0
    def find_linked_elements(self):
        with DryAction("Search for linked elements",
                       clear_after_rollback=True):
            linked_element_ids = doc.Delete(self._rvt_type.Id)

        return linked_element_ids
Ejemplo n.º 9
0
from revitutils import doc

# noinspection PyUnresolvedReferences
from Autodesk.Revit.DB import Transaction, BuiltInCategory, GraphicsStyleType
# noinspection PyUnresolvedReferences
from Autodesk.Revit.UI import TaskDialog

if doc.IsFamilyDocument:
    det_item_cat = doc.OwnerFamily.FamilyCategory

    if 'Detail Item' in det_item_cat.Name:
        with Transaction(doc, 'Wipe Detail Item Categories') as t:
            t.Start()

            for sub_cat in det_item_cat.SubCategories:
                logger.debug('Removing sub category: {}'.format(sub_cat.Name))
                try:
                    doc.Delete(sub_cat.Id)
                    pass
                except:
                    logger.warning('Can not delete sub category: {}'.format(
                        sub_cat.Name))
                    continue

            t.Commit()
    else:
        TaskDialog.Show('pyRevit', 'Family must be of type Detail Item.')
else:
    TaskDialog.Show('pyRevit',
                    'This script works only on an active family editor.')
Ejemplo n.º 10
0
"""Lists all the elements that are tied to the selected element. For example elements tags or dimensions."""

from scriptutils import this_script
from revitutils import doc, selection

# noinspection PyUnresolvedReferences
from Autodesk.Revit.DB import Transaction

if not selection.is_empty:
    t = Transaction(doc, "Search for linked elements")
    t.Start()

    print("Searching for all objects tied to ELEMENT ID: {0}...".format(
        selection.first.Id))
    linked_elements_list = doc.Delete(selection.first.Id)

    t.RollBack()

    for elId in linked_elements_list:
        el = doc.GetElement(elId)
        if el and elId in selection.element_ids:
            elid_link = this_script.output.linkify(elId)
            print("ID: {0}\t\tTYPE: {1} ( selected object )".format(
                elid_link,
                el.GetType().Name))
        elif el:
            elid_link = this_script.output.linkify(elId)
            print("ID: {0}\t\tTYPE: {1}".format(elid_link, el.GetType().Name))