|
1 | | -# these commands get executed in the current scope |
2 | | -# of each new shell (but not for canned commands) |
3 | | -from Autodesk.Revit.DB import * |
4 | | -from Autodesk.Revit.DB.Architecture import * |
5 | | -from Autodesk.Revit.DB.Analysis import * |
6 | | - |
7 | | -uidoc = __revit__.ActiveUIDocument |
8 | | -doc = __revit__.ActiveUIDocument.Document |
9 | | - |
10 | | -from Autodesk.Revit.UI import TaskDialog |
11 | | -from Autodesk.Revit.UI import UIApplication |
12 | | - |
13 | | - |
14 | | -def alert(msg): |
15 | | - TaskDialog.Show('RevitPythonShell', msg) |
16 | | - |
17 | | - |
18 | | -def quit(): |
19 | | - __window__.Close() |
20 | | -exit = quit |
21 | | - |
22 | | - |
23 | | -def get_selected_elements(doc): |
24 | | - """API change in Revit 2016 makes old method throw an error""" |
25 | | - try: |
26 | | - # Revit 2016 |
27 | | - return [doc.GetElement(id) |
28 | | - for id in __revit__.ActiveUIDocument.Selection.GetElementIds()] |
29 | | - except: |
30 | | - # old method |
31 | | - return list(__revit__.ActiveUIDocument.Selection.Elements) |
32 | | -selection = get_selected_elements(doc) |
33 | | -# convenience variable for first element in selection |
34 | | -if len(selection): |
35 | | - s0 = selection[0] |
36 | | - |
37 | | -#------------------------------------------------------------------------------ |
38 | | -import clr |
39 | | -from Autodesk.Revit.DB import ElementSet, ElementId |
40 | | - |
41 | | -class RevitLookup(object): |
42 | | - def __init__(self, uiApplication): |
43 | | - ''' |
44 | | - for RevitSnoop to function properly, it needs to be instantiated |
45 | | - with a reference to the Revit Application object. |
46 | | - ''' |
47 | | - # find the RevitLookup plugin |
48 | | - try: |
49 | | - rlapp = [app for app in uiApplication.LoadedApplications |
50 | | - if app.GetType().Namespace == 'RevitLookup' |
51 | | - and app.GetType().Name == 'App'][0] |
52 | | - except IndexError: |
53 | | - self.RevitLookup = None |
54 | | - return |
55 | | - # tell IronPython about the assembly of the RevitLookup plugin |
56 | | - clr.AddReference(rlapp.GetType().Assembly) |
57 | | - import RevitLookup |
58 | | - self.RevitLookup = RevitLookup |
59 | | - # See note in CollectorExt.cs in the RevitLookup source: |
60 | | - self.RevitLookup.Snoop.CollectorExts.CollectorExt.m_app = uiApplication |
61 | | - self.revit = uiApplication |
62 | | - |
63 | | - def lookup(self, element): |
64 | | - if not self.RevitLookup: |
65 | | - print 'RevitLookup not installed. Visit https://github.com/jeremytammik/RevitLookup to install.' |
66 | | - return |
67 | | - if isinstance(element, int): |
68 | | - element = self.revit.ActiveUIDocument.Document.GetElement(ElementId(element)) |
69 | | - if isinstance(element, ElementId): |
70 | | - element = self.revit.ActiveUIDocument.Document.GetElement(element) |
71 | | - if isinstance(element, list): |
72 | | - elementSet = ElementSet() |
73 | | - for e in element: |
74 | | - elementSet.Insert(e) |
75 | | - element = elementSet |
76 | | - form = self.RevitLookup.Snoop.Forms.Objects(element) |
77 | | - form.ShowDialog() |
78 | | -_revitlookup = RevitLookup(__revit__) |
79 | | -def lookup(element): |
80 | | - _revitlookup.lookup(element) |
81 | | - |
82 | | -#------------------------------------------------------------------------------ |
83 | | - |
84 | | -# a fix for the __window__.Close() bug introduced with the non-modal console |
85 | | -class WindowWrapper(object): |
86 | | - def __init__(self, win): |
87 | | - self.win = win |
88 | | - |
89 | | - def Close(self): |
90 | | - self.win.Dispatcher.Invoke(lambda *_: self.win.Close()) |
91 | | - |
92 | | - def __getattr__(self, name): |
93 | | - return getattr(self.win, name) |
94 | | -__window__ = WindowWrapper(__window__) |
| 1 | +# these commands get executed in the current scope |
| 2 | +# of each new shell (but not for canned commands) |
| 3 | +from Autodesk.Revit.DB import * |
| 4 | +from Autodesk.Revit.DB.Architecture import * |
| 5 | +from Autodesk.Revit.DB.Analysis import * |
| 6 | + |
| 7 | +uidoc = __revit__.ActiveUIDocument |
| 8 | +doc = __revit__.ActiveUIDocument.Document |
| 9 | + |
| 10 | +from Autodesk.Revit.UI import TaskDialog |
| 11 | +from Autodesk.Revit.UI import UIApplication |
| 12 | + |
| 13 | + |
| 14 | +def alert(msg): |
| 15 | + TaskDialog.Show('RevitPythonShell', msg) |
| 16 | + |
| 17 | + |
| 18 | +def quit(): |
| 19 | + __window__.Close() |
| 20 | +exit = quit |
| 21 | + |
| 22 | + |
| 23 | +def get_selected_elements(doc): |
| 24 | + """API change in Revit 2016 makes old method throw an error""" |
| 25 | + try: |
| 26 | + # Revit 2016 |
| 27 | + return [doc.GetElement(id) |
| 28 | + for id in __revit__.ActiveUIDocument.Selection.GetElementIds()] |
| 29 | + except: |
| 30 | + # old method |
| 31 | + return list(__revit__.ActiveUIDocument.Selection.Elements) |
| 32 | +selection = get_selected_elements(doc) |
| 33 | +# convenience variable for first element in selection |
| 34 | +if len(selection): |
| 35 | + s0 = selection[0] |
| 36 | + |
| 37 | +#------------------------------------------------------------------------------ |
| 38 | +import clr |
| 39 | +from Autodesk.Revit.DB import ElementSet, ElementId |
| 40 | + |
| 41 | +class RevitLookup(object): |
| 42 | + def __init__(self, uiApplication): |
| 43 | + ''' |
| 44 | + for RevitSnoop to function properly, it needs to be instantiated |
| 45 | + with a reference to the Revit Application object. |
| 46 | + ''' |
| 47 | + # find the RevitLookup plugin |
| 48 | + try: |
| 49 | + rlapp = [app for app in uiApplication.LoadedApplications |
| 50 | + if app.GetType().Namespace == 'RevitLookup' |
| 51 | + and app.GetType().Name == 'App'][0] |
| 52 | + except IndexError: |
| 53 | + self.RevitLookup = None |
| 54 | + return |
| 55 | + # tell IronPython about the assembly of the RevitLookup plugin |
| 56 | + clr.AddReference(rlapp.GetType().Assembly) |
| 57 | + import RevitLookup |
| 58 | + self.RevitLookup = RevitLookup |
| 59 | + # See note in CollectorExt.cs in the RevitLookup source: |
| 60 | + self.RevitLookup.Snoop.CollectorExts.CollectorExt.m_app = uiApplication |
| 61 | + self.revit = uiApplication |
| 62 | + |
| 63 | + def lookup(self, element): |
| 64 | + if not self.RevitLookup: |
| 65 | + print 'RevitLookup not installed. Visit https://github.com/jeremytammik/RevitLookup to install.' |
| 66 | + return |
| 67 | + if isinstance(element, int): |
| 68 | + element = self.revit.ActiveUIDocument.Document.GetElement(ElementId(element)) |
| 69 | + if isinstance(element, ElementId): |
| 70 | + element = self.revit.ActiveUIDocument.Document.GetElement(element) |
| 71 | + if isinstance(element, list): |
| 72 | + elementSet = ElementSet() |
| 73 | + for e in element: |
| 74 | + elementSet.Insert(e) |
| 75 | + element = elementSet |
| 76 | + form = self.RevitLookup.Snoop.Forms.Objects(element) |
| 77 | + form.ShowDialog() |
| 78 | +_revitlookup = RevitLookup(__revit__) |
| 79 | +def lookup(element): |
| 80 | + _revitlookup.lookup(element) |
| 81 | + |
| 82 | +#------------------------------------------------------------------------------ |
| 83 | + |
| 84 | +# a fix for the __window__.Close() bug introduced with the non-modal console |
| 85 | +class WindowWrapper(object): |
| 86 | + def __init__(self, win): |
| 87 | + self.win = win |
| 88 | + |
| 89 | + def Close(self): |
| 90 | + self.win.Dispatcher.Invoke(lambda *_: self.win.Close()) |
| 91 | + |
| 92 | + def __getattr__(self, name): |
| 93 | + return getattr(self.win, name) |
| 94 | +__window__ = WindowWrapper(__window__) |
0 commit comments