Example #1
0
def get_dest_docs():
    class DestDoc:
        def __init__(self, doc):
            self.state = False
            self.dest_doc = doc
            self.name = self.dest_doc.Title
        def __nonzero__(self):
            return self.state

    # find open documents other than the active doc
    open_docs = [d for d in __revit__.Application.Documents if not d.IsLinked]
    open_docs.remove(activedoc)
    if len(open_docs) < 1:
        error_and_close('Only one active document is found. ' \
                        'At least two documents must be open. ' \
                        'Operation cancelled.')

    return_options = \
        SelectFromCheckBoxes.show([DestDoc(x) for x in open_docs],
                                   title='Select Destination Documents',
                                   button_name='OK')

    if return_options:
        return [x.dest_doc for x in return_options if x]
    else:
        sys.exit(0)
Example #2
0
def get_source_sheets():
    class SheetToCopy:
        def __init__(self, sheet):
            self.state = False
            self.sheet = sheet
            self.name = '{} - {}'.format(sheet.SheetNumber, sheet.Name)
            self.number = sheet.SheetNumber
        def __nonzero__(self):
            return self.state

    all_sheets = FilteredElementCollector(activedoc) \
                 .OfClass(ViewSheet) \
                 .WhereElementIsNotElementType() \
                 .ToElements()

    return_options = \
        SelectFromCheckBoxes.show(sorted([SheetToCopy(x) for x in all_sheets],
                                  key=lambda x: x.number),
                                  title='Select Sheets to be Copied',
                                  width=500,
                                  button_name='Copy Sheets')

    if return_options:
        return [x.sheet for x in return_options if x]
    else:
        sys.exit(0)
Example #3
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)))
Example #4
0
def get_user_options():
    op_set = OptionSet()
    return_options = \
        SelectFromCheckBoxes.show([getattr(op_set, x) for x in dir(op_set) if x.startswith('op_')],
                                  title='Select Copy Options',
                                  button_name='Copy Now')

    if not return_options:
        sys.exit(0)

    return op_set
Example #5
0
    ("Sheet ID"), ('Sub-Discipline - Sheet'), ('View Type - Sheet'),
    ("View Name"), ('View ID'), ('Sub-Disicpline - View'), ('View Type'),
    ('View Level'), ('View Uniclass Group'), ('View Uniclass Sub Group'),
    ('Location on Sheet'), ('Sheet Outline')
])

# selSheets = forms.select_sheets(title='Select Target Sheets',
# button_name='Select Sheets')

allSheets = FilteredElementCollector(doc).OfClass(ViewSheet).ToElements()

#select multiple
selected = []
return_options = SelectFromCheckBoxes.show(sorted(
    [SheetOption(x) for x in allSheets], key=lambda x: x.number),
                                           title="Select Sheets",
                                           button_name="Select Sheets",
                                           width=800)
if return_options:
    selected = [x.unwrap() for x in return_options if x.state]

sheetList = list(selected)

for s in sheetList:

    sheetSubDiscipline = s.LookupParameter("Sub-Discipline").AsString()
    sheetViewType = s.LookupParameter("View type").AsString()

    if s.GetAllPlacedViews():
        placedViews = s.GetAllPlacedViews()
Example #6
0
wipe_options = []

# noinspection PyUnresolvedReferences
import wipeactions

for mem in inspect.getmembers(wipeactions):
    moduleobject = mem[1]
    if inspect.isfunction(moduleobject):
        if moduleobject.__doc__:
            wipe_options.append(
                WipeOption(moduleobject.__doc__, wipe_action=moduleobject))

# ask user for wipe actions
return_options = SelectFromCheckBoxes.show(sorted(wipe_options,
                                                  key=lambda x: x.name),
                                           title='Wipe Options',
                                           width=500,
                                           button_name='Wipe Model')

if return_options:
    dependent_actions = [
        wipe_act for wipe_act in return_options if wipe_act.is_dependent
    ]
    not_dependent_actions = [
        wipe_act for wipe_act in return_options if not wipe_act.is_dependent
    ]

    for actions in [dependent_actions, not_dependent_actions]:
        for wipe_act in actions:
            if wipe_act:
                logger.debug('Calling: {}'.format(wipe_act))
Example #7
0
    if vtid > 0:
        usedvtemp.add(vtid)

unusedvtemp = vtemp - usedvtemp

if unusedvtemp:
    # ask user for wipe actions
    class ViewTemplateToPurge:
        def __init__(self, template_elid):
            self.state = False
            self.template_el = doc.GetElement(ElementId(template_elid))
            self.name = self.template_el.Name

    return_options = SelectFromCheckBoxes.show(
        [ViewTemplateToPurge(x) for x in unusedvtemp],
        title='Select View Templates to Purge',
        width=500,
        button_name='Purge View Templates')

    if return_options:
        t = Transaction(doc, 'Purge Unused View Templates')
        t.Start()

        for vtp in return_options:
            if vtp.state:
                print('Purging View Template: {0}\t{1}'.format(
                    vtp.template_el.Id, vtp.name))
                doc.Delete(vtp.template_el.Id)

        # res = TaskDialog.Show('pyrevit',
        #                       'Are you sure you want to remove these view templates?',
Example #8
0
        genLevel = "<No Level>"
        if doc.GetElement(self.item.ViewTemplateId):
            vtName = doc.GetElement(self.item.ViewTemplateId).Name
        if self.item.GenLevel:
            genLevel = self.item.GenLevel.Name

        return '{} ({})  -----  [{}] ---  [{}]'.format(self.item.ViewName,
                                                       self.item.ViewType,
                                                       str(vtName), genLevel)


#select multiple
selected = []
return_options = SelectFromCheckBoxes.show(sorted(
    [ViewOption(x) for x in views], key=lambda x: x.name),
                                           title="Select Views to Rename",
                                           button_name="Rename Selected Views",
                                           width=800)
if return_options:
    selected = [x.unwrap() for x in return_options if x.state]

viewList = list(selected)

log = []

t = Transaction(doc)
t.Start(__title__)

for i in viewList:
    if i.GenLevel:
        floorPlanView = i
Example #9
0
def main():
    global PURGE_RESULTS_CSV
    global START_TIME
    global PURGE_NOTUSED_FAMILIES

    # q = TaskDialog.Show(__title__, "Purge not used families?",
    #                             TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel)
    # if str(q) == "Ok":
    #     PURGE_NOTUSED_FAMILIES = True

    purgers = Purgers()
    directory = create_directory(doc.Title)
    options = []
    selected_purgers = []

    for f in dir(purgers):
        func = purgers.__getattribute__(f)
        if type(func) == types.MethodType and f[0] != "_":

            opt = CheckBoxFunc(func, True)
            options.append(opt)
    if len(options) > 1:
        all_checkboxes = SelectFromCheckBoxes.show(
            options,
            title='Select cleaners to Purge',
            width=300,
            button_name='Purge!')
        if all_checkboxes:
            selected_purgers = [
                c.func for c in all_checkboxes if c.state == True
            ]
    else:
        selected_purgers = [c.func for c in options]

    if len(selected_purgers) > 0:
        PURGED_COUNT = 0
        level = 0
        max_level = 99
        if doc.Title[-4:] == ".rfa":
            level = 1

        if __shiftclick__:
            max_level = 1

        START_TIME = time.time()
        print(directory)

        csv_line = [
            "Level", "Category", "Family name", "Size before", "Size after",
            "Size diff"
        ]

        for pk in selected_purgers:
            csv_line.append("Purged: " + str(pk.__name__))

        PURGE_RESULTS_CSV.append(csv_line)

        process_purge(doc,
                      selected_purgers,
                      level=level,
                      max_level=max_level,
                      directory=directory)
        this_script.output.set_title("%s - Write CSV" % (window_title, ))
        write_csv(directory)
        this_script.output.set_title("%s - Done" % (window_title, ))

        print("\n\nFinished")
        for r in PURGE_RESULTS.keys():
            c = PURGE_RESULTS[r]
            print("%s: %d" % (r, c))
            PURGED_COUNT += c
        print('\nTOTAL purged: %d' % PURGED_COUNT)
        print('SIZE DIFFERENCE: %.3f Mb' % PURGE_SIZES_SUM)

        print("\n\n--- %s ---" % (time_format(time_elapsed())))

        this_script.output.update_progress(100, 100)

    else:
        print("nothing selected")
Example #10
0
class ViewTemplateOption(BaseCheckBoxItem):
    def __init__(self, vt_param):
        super(ViewTemplateOption, self).__init__(vt_param)

    @property
    def name(self):

        return '{}  '.format(self.item.Definition.Name)


#select multiple
selected = []
return_options = SelectFromCheckBoxes.show(
    sorted([ViewOption(x) for x in viewTemplates], key=lambda x: x.name),
    title="Select View Templates to Modify",
    button_name="Select",
    width=800)
if return_options:
    selected = [x.unwrap() for x in return_options if x.state]

viewTemplates = list(selected)

vtParams = viewTemplates[0].Parameters

selected = []
return_options = SelectFromCheckBoxes.show(
    sorted([ViewTemplateOption(x) for x in vtParams], key=lambda x: x.name),
    title="Select View Template Parameters to set to UnControlled",
    button_name="Select",
    width=800)
Example #11
0
class ViewOption(BaseCheckBoxItem):
    def __init__(self, view_element):
        super(ViewOption, self).__init__(view_element)

    @property
    def name(self):

        return '{} ({}) '.format(self.item.ViewName, self.item.ViewType)


#select multiple
selected = []
return_options = SelectFromCheckBoxes.show(
    sorted([ViewOption(x) for x in viewTemplates], key=lambda x: x.name),
    title="Select View Templates to Create Views From",
    button_name="Create 3D Views for Selected Templates",
    width=800)
if return_options:
    selected = [x.unwrap() for x in return_options if x.state]

viewTemplates = list(selected)

levels = FilteredElementCollector(doc).OfClass(Level).ToElements()

viewFamilyTypes = FilteredElementCollector(doc).OfClass(
    ViewFamilyType).ToElements()

#create Floor Plan Views for each Level and View Template
name = "3D View"
id = -1
Example #12
0
def main():
    allowed_types = [
        ViewPlan,
        View3D,
        ViewSection,
        ViewSheet,
        ViewDrafting
    ]

    selection = uidoc.Selection.GetElementIds()
    if type(doc.ActiveView)!=View:
        active_view = doc.ActiveView
    else:
        active_view = doc.GetElement(selection[0])
        if type(active_view) not in allowed_types:
            logger.error('Selected view is not allowed. Please select or open view from which you want to copy template settings VG Overrides - Filters')
            return
    logger.info('Source view selected: %s id%s' % (active_view.Name, active_view.Id.ToString()))
    active_template = doc.GetElement(active_view.ViewTemplateId)
    logger.info('Source template: %s id%s' % (active_template.Name, active_template.Id.ToString()))

    active_template_filters = active_template.GetFilters()
    
    # print(active_template_filter_rules)
    # return

    selset = read_states()
    # print(selset)
    vt_dict = get_view_templates(doc,selset=selset)
    active_template_filters_ch = get_view_filters(doc,active_template)

    all_checkboxes = SelectFromCheckBoxes.show(active_template_filters_ch)
    sel_checkboxes_filter = []
    # now you can check the state of checkboxes in your program
    for checkbox in all_checkboxes:
        if checkbox:
            sel_checkboxes_filter.append(checkbox)
    if len(sel_checkboxes_filter)==0:
        return


    all_checkboxes = SelectFromCheckBoxes.show(vt_dict)
    sel_checkboxes = []
    # now you can check the state of checkboxes in your program
    for checkbox in all_checkboxes:
        if checkbox:
            sel_checkboxes.append(checkbox)
    if len(sel_checkboxes)==0:
        return
    write_state(sel_checkboxes)


    t = Transaction(doc)
    t.Start("Copy VG")

    for ch in sel_checkboxes:
        vt = doc.GetElement(ch.id)

        if vt.Id == active_template.Id:
            print('current template found')
            continue

        for f in sel_checkboxes_filter:
            fId = f.id
            try:
                vt.RemoveFilter(fId)
                logger.info('filter %s deleted from template %s' % (fId.ToString(), vt.Name))
            except:
                pass
            try:
                fr = active_template.GetFilterOverrides(fId)
                vt.SetFilterOverrides(fId,fr)
            except Exception as e:
                logger.warning('filter not aplied to active view %s\n%s' % (fId.ToString(), e))
    t.Commit()
    print("finished")