Skip to content

Support Ironpython3.4 #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 24 additions & 64 deletions RevitPythonShell/DefaultConfig/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ def alert(msg):

def quit():
__window__.Close()


exit = quit


def GetSelectedElements(doc):
def get_selected_elements(doc):
"""API change in Revit 2016 makes old method throw an error"""
try:
# Revit 2016
Expand All @@ -33,7 +31,7 @@ def GetSelectedElements(doc):
return list(__revit__.ActiveUIDocument.Selection.Elements)


selection = GetSelectedElements(doc)
selection = get_selected_elements(doc)
# convenience variable for first element in selection
if len(selection):
s0 = selection[0]
Expand All @@ -53,81 +51,43 @@ def __init__(self, uiApplication):
try:
rlapp = [app for app in uiApplication.LoadedApplications
if app.GetType().Namespace == 'RevitLookup'
and app.GetType().Name == 'Application'][0]
and app.GetType().Name == 'App'][0]
except IndexError:
self.RevitLookup = None
return
# tell IronPython about the assembly of the RevitLookup plugin
clr.AddReference(rlapp.GetType().Assembly)
import RevitLookup
self.RevitLookup = RevitLookup
# See note in CollectorExt.cs in the RevitLookup source:
try:
self.RevitLookup.Snoop.CollectorExts.CollectorExt.m_app = uiApplication
except TypeError: # assigning m_app is now not required and even not possible
pass
self.revit = uiApplication

def IsInstalled(self):
def lookup(self, element):
if not self.RevitLookup:
print('RevitLookup not installed. Visit https://github.com/jeremytammik/RevitLookup to install.')
return False
return True

def SnoopCurrentSelection(self):
if self.IsInstalled():
form = self.RevitLookup.Views.ObjectsView()
form.SnoopAndShow(self.RevitLookup.Core.Selector.SnoopCurrentSelection)

def SnoopElement(self,element):
if self.IsInstalled():
if element is None:
print("element null object, Please input element to snoop")
return
if isinstance(element, int):
element = doc.GetElement(ElementId(element))
if isinstance(element, ElementId):
element = doc.GetElement(element)
if isinstance(element, list):
elementSet = ElementSet()
for e in element:
elementSet.Insert(e)
form = self.RevitLookup.Views.ObjectsView(elementSet)
self.RevitLookup.Core.ModelessWindowFactory.Show(form)
pass
form = self.RevitLookup.Views.ObjectsView(element)
self.RevitLookup.Core.ModelessWindowFactory.Show(form)

def SnoopActiveView():
if self.IsInstalled():
self.SnoopElement(doc.ActiveView)

def SnoopDb(self):
if self.IsInstalled():
form = self.RevitLookup.Views.ObjectsView()
form.SnoopAndShow(self.RevitLookup.Core.Selector.SnoopDb)
return
if isinstance(element, int):
element = self.revit.ActiveUIDocument.Document.GetElement(ElementId(element))
if isinstance(element, ElementId):
element = self.revit.ActiveUIDocument.Document.GetElement(element)
if isinstance(element, list):
elementSet = ElementSet()
for e in element:
elementSet.Insert(e)
element = elementSet
form = self.RevitLookup.Snoop.Forms.Objects(element)
form.ShowDialog()


_revitlookup = RevitLookup(__revit__)


def SnoopCurrentSelection():
_revitlookup.SnoopCurrentSelection()


'''
## Example :
## _revitlookup.SnoopElement(doc.ActiveView)
## _revitlookup.SnoopElement(959510)
## _revitlookup.SnoopElement(doc.ActiveView.Id)
'''


def SnoopElement(element):
_revitlookup.SnoopElement(element)


def SnoopActiveView():
_revitlookup.SnoopActiveView()


def SnoopDb():
_revitlookup.SnoopDb()

def lookup(element):
_revitlookup.lookup(element)

# ------------------------------------------------------------------------------

Expand Down