This repository was archived by the owner on Jan 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
89 lines (74 loc) · 2.88 KB
/
script.py
File metadata and controls
89 lines (74 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import os
from pyrevit import forms, script
# Custom modules in lib/
from file_utils import FileFinder
from family_utils import FamilyLoader
logger = script.get_logger()
output = script.get_output()
# Get directory with families
directory = forms.pick_folder("Select parent folder of families")
logger.debug('Selected parent folder: {}'.format(directory))
if directory is None:
logger.debug('No directory selected. Calling script.exit')
script.exit()
# Find family files in directory
finder = FileFinder(directory)
finder.search('*.rfa')
# Excluding backup files
backup_pattern = r'^.*\.\d{4}\.rfa$'
finder.exclude_by_pattern(backup_pattern)
paths = finder.paths
# Dictionary to look up absolute paths by relative paths
path_dict = dict()
for path in paths:
path_dict.update({os.path.relpath(path, directory): path})
# User input -> Select families from directory
family_select_options = sorted(
path_dict.keys(),
key=lambda x: (x.count(os.sep), x)) # Sort by nesting level
selected_families = forms.SelectFromList.show(
family_select_options,
title="Select Families",
width=500,
button_name="Load Families",
multiselect=True)
if selected_families is None:
logger.debug('No families selected. Calling script.exit()')
script.exit()
logger.debug('Selected Families: {}'.format(selected_families))
# Dictionary to look up FamilyLoader method by selected option
family_loading_options = {
"Load all types": "load_all",
"Load types by selecting individually": "load_selective"}
selected_loading_option = forms.CommandSwitchWindow.show(
family_loading_options.keys(),
message='Select loading option:',)
if selected_loading_option is None:
logger.debug('No loading option selected. Calling script.exit()')
script.exit()
# User input -> Select loading option (load all, load certain symbols)
logger.debug('Selected loading option: {}'.format(selected_loading_option))
laoding_option = family_loading_options[selected_loading_option]
# Feedback on already loaded families
already_loaded = set()
# Loading selected families
max_value = len(selected_families)
with forms.ProgressBar(title='Loading Family {value} of {max_value}',
cancellable=True) as pb:
for count, family_path in enumerate(selected_families, 1):
if pb.cancelled:
break
pb.update_progress(count, max_value)
family = FamilyLoader(path_dict[family_path])
logger.debug('Loading family: {}'.format(family.name))
loaded = family.is_loaded
if loaded:
logger.debug('Family is already loaded: {}'.format(family.path))
already_loaded.add(family)
continue
getattr(family, laoding_option)()
# Feedback on already loaded families
if len(already_loaded) != 0:
output.print_md('### Families that were already loaded:')
for family in sorted(already_loaded):
print(family.path)