-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
115 lines (89 loc) · 2.94 KB
/
main.py
File metadata and controls
115 lines (89 loc) · 2.94 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import os
import inspect
import importlib
from collections import OrderedDict
import xml.etree.ElementTree as ET
from api import DOC, APP
HEADER = r'''
____ _ _ ____ _ _
| _ \ _ _| |_| |__ ___ _ __ / ___| ___ _ __(_)_ __ | |_ ___
| |_) | | | | __| '_ \ / _ \| '_ \ \___ \ / __| '__| | '_ \| __/ __|
| __/| |_| | |_| | | | (_) | | | | ___) | (__| | | | |_) | |_\__ \
|_| \__, |\__|_| |_|\___/|_| |_| |____/ \___|_| |_| .__/ \__|___/
|___/ |_|
'''
def get_functions(start_dir):
functions = OrderedDict()
stop_modules = ['scratch', 'main', 'test_runner', 'api']
for mname in os.listdir(start_dir):
basename, ext = os.path.splitext(mname)
if not ext == '.py':
continue
if basename in stop_modules:
continue
m = importlib.import_module(basename)
for name, obj in inspect.getmembers(m):
if not inspect.isfunction(obj):
continue
if name.startswith('_'):
continue
if not obj.__doc__:
continue
if m not in functions:
functions[m] = []
functions[m].append(obj)
return functions
def get_index_input(prompt):
index = 0
while 1:
try:
index = int(raw_input(prompt)) - 1
break
except ValueError:
print('Invalid index')
return index
def prettify(text):
return (' '.join(text.split('_'))).title()
def ui(functions):
print(HEADER)
for i, module in enumerate(functions, 1):
print('{} {}'.format(i, module.__name__.title()))
module_index = get_index_input('Which module?: ')
module = functions.keys()[module_index]
print('')
for i, func in enumerate(functions[module], 1):
print('{} {}'.format(i, prettify(func.__name__)))
print(' ' + (func.__doc__.strip() or ''))
print('')
func_index = get_index_input('Which function?: ')
func = functions[module][func_index]
print('')
# Execute function
try:
retval = func(DOC)
print('{} executed successfully'.format(prettify(func.__name__)))
except Exception as e:
print(e)
print('')
choice = raw_input('"q" to exit or any key to continue: ')
if choice.lower() == 'q':
__window__.Close()
return
else:
ui(functions)
def get_curdir():
curdir = None
xml_path = os.path.join(
os.environ['APPDATA'],
'RevitPythonShell' + APP.VersionNumber,
'RevitPythonShell.xml')
root = ET.parse(open(xml_path)).getroot()
for command in root.iter('Command'):
if command.attrib['name'] == 'Revit Scripts':
path = command.attrib['src']
curdir = os.path.dirname(path)
return curdir
if __name__ == '__main__':
curdir = get_curdir()
ui(get_functions(curdir))
print('Finished')