Skip to content

Commit 0b68e84

Browse files
authored
Merge pull request #124 from chuongmep/dev
Update Support use method from revitlookup to snoop
2 parents c51e5ad + 3d2f455 commit 0b68e84

File tree

1 file changed

+64
-21
lines changed
  • RevitPythonShell/DefaultConfig

1 file changed

+64
-21
lines changed

RevitPythonShell/DefaultConfig/init.py

+64-21
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ def alert(msg):
1717

1818
def quit():
1919
__window__.Close()
20+
21+
2022
exit = quit
2123

2224

23-
def get_selected_elements(doc):
25+
def GetSelectedElements(doc):
2426
"""API change in Revit 2016 makes old method throw an error"""
2527
try:
2628
# Revit 2016
@@ -31,7 +33,7 @@ def get_selected_elements(doc):
3133
return list(__revit__.ActiveUIDocument.Selection.Elements)
3234

3335

34-
selection = get_selected_elements(doc)
36+
selection = GetSelectedElements(doc)
3537
# convenience variable for first element in selection
3638
if len(selection):
3739
s0 = selection[0]
@@ -51,40 +53,81 @@ def __init__(self, uiApplication):
5153
try:
5254
rlapp = [app for app in uiApplication.LoadedApplications
5355
if app.GetType().Namespace == 'RevitLookup'
54-
and app.GetType().Name == 'App'][0]
56+
and app.GetType().Name == 'Application'][0]
5557
except IndexError:
5658
self.RevitLookup = None
5759
return
5860
# tell IronPython about the assembly of the RevitLookup plugin
5961
clr.AddReference(rlapp.GetType().Assembly)
6062
import RevitLookup
6163
self.RevitLookup = RevitLookup
62-
# See note in CollectorExt.cs in the RevitLookup source:
63-
self.RevitLookup.Snoop.CollectorExts.CollectorExt.m_app = uiApplication
64-
self.revit = uiApplication
6564

66-
def lookup(self, element):
65+
def IsInstalled(self):
6766
if not self.RevitLookup:
6867
print('RevitLookup not installed. Visit https://github.com/jeremytammik/RevitLookup to install.')
69-
return
70-
if isinstance(element, int):
71-
element = self.revit.ActiveUIDocument.Document.GetElement(ElementId(element))
72-
if isinstance(element, ElementId):
73-
element = self.revit.ActiveUIDocument.Document.GetElement(element)
74-
if isinstance(element, list):
75-
elementSet = ElementSet()
76-
for e in element:
77-
elementSet.Insert(e)
78-
element = elementSet
79-
form = self.RevitLookup.Snoop.Forms.Objects(element)
80-
form.ShowDialog()
68+
return False
69+
return True
70+
71+
def SnoopCurrentSelection(self):
72+
if self.IsInstalled():
73+
form = self.RevitLookup.Views.ObjectsView()
74+
form.SnoopAndShow(self.RevitLookup.Core.Selector.SnoopCurrentSelection)
75+
76+
def SnoopElement(self,element):
77+
if self.IsInstalled():
78+
if element is None:
79+
print("element null object, Please input element to snoop")
80+
return
81+
if isinstance(element, int):
82+
element = doc.GetElement(ElementId(element))
83+
if isinstance(element, ElementId):
84+
element = doc.GetElement(element)
85+
if isinstance(element, list):
86+
elementSet = ElementSet()
87+
for e in element:
88+
elementSet.Insert(e)
89+
form = self.RevitLookup.Views.ObjectsView(elementSet)
90+
self.RevitLookup.Core.ModelessWindowFactory.Show(form)
91+
pass
92+
form = self.RevitLookup.Views.ObjectsView(element)
93+
self.RevitLookup.Core.ModelessWindowFactory.Show(form)
94+
95+
def SnoopActiveView():
96+
if self.IsInstalled():
97+
self.SnoopElement(doc.ActiveView)
98+
99+
def SnoopDb(self):
100+
if self.IsInstalled():
101+
form = self.RevitLookup.Views.ObjectsView()
102+
form.SnoopAndShow(self.RevitLookup.Core.Selector.SnoopDb)
81103

82104

83105
_revitlookup = RevitLookup(__revit__)
84106

85107

86-
def lookup(element):
87-
_revitlookup.lookup(element)
108+
def SnoopCurrentSelection():
109+
_revitlookup.SnoopCurrentSelection()
110+
111+
112+
'''
113+
## Example :
114+
## _revitlookup.SnoopElement(doc.ActiveView)
115+
## _revitlookup.SnoopElement(959510)
116+
## _revitlookup.SnoopElement(doc.ActiveView.Id)
117+
'''
118+
119+
120+
def SnoopElement(element):
121+
_revitlookup.SnoopElement(element)
122+
123+
124+
def SnoopActiveView():
125+
_revitlookup.SnoopActiveView()
126+
127+
128+
def SnoopDb():
129+
_revitlookup.SnoopDb()
130+
88131

89132
# ------------------------------------------------------------------------------
90133

0 commit comments

Comments
 (0)