Skip to content

Commit

Permalink
Fixes #32 - Added __getitem__ to selection
Browse files Browse the repository at this point in the history
  • Loading branch information
gtalarico committed Nov 22, 2017
1 parent 75bf228 commit 2753562
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
4 changes: 4 additions & 0 deletions notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

### 1.7.3
* Added Get by Index to Selection (issues #32)
* Converted ElementSet internal storage to list instead of set to allow ordered sequence

### 1.7.2
* Fixed: Collector.get_element_ids() Typo
* Fix: XYZ can now take regular DB.XYZ
Expand Down
2 changes: 1 addition & 1 deletion rpw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"""

__title__ = 'revitpythonwrapper'
__version__ = '1.7.2'
__version__ = '1.7.3'
__maintainer__ = ['Gui Talarico', 'Ehsan Iran-Nejad']
__license__ = 'MIT'
__contact__ = 'github.com/gtalarico/revitpythonwrapper'
Expand Down
15 changes: 8 additions & 7 deletions rpw/db/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ElementSet(BaseObject):

def __init__(self, elements_or_ids=None, doc=revit.doc):
self.doc = doc
self._element_id_set = set()
self._element_id_set = []
if elements_or_ids:
self.add(elements_or_ids)

Expand All @@ -49,7 +49,8 @@ def add(self, elements_or_ids):
"""
element_ids = to_element_ids(elements_or_ids)
for id_ in element_ids:
self._element_id_set.add(id_)
if id_ not in self._element_id_set:
self._element_id_set.append(id_)

def pop(self, element_reference, wrapped=True):
"""
Expand All @@ -69,7 +70,7 @@ def pop(self, element_reference, wrapped=True):

def clear(self):
""" Clears Set """
self._element_id_set = set()
self._element_id_set = []

@property
def _elements(self):
Expand Down Expand Up @@ -161,7 +162,7 @@ def __iter__(self):

def __getitem__(self, element_reference):
"""
Get Element from set
Get Element from set from an element ElementId
Args:
element_reference (DB.Element, DB.ElementID)
Expand Down Expand Up @@ -207,8 +208,6 @@ class ElementCollection(BaseObject):
True
>>> element_set.clear()
NOTE: Similar to DB.ElementCollection, doesnt wrap since there is no advantage
Args:
(`DB.Element`, `DB.ElementID`, optional): Elements or Element Ids.
"""
Expand Down Expand Up @@ -365,7 +364,9 @@ def __bool__(self):
return bool(self._elements)

def __repr__(self, data=None):
return super(ElementCollection, self).__repr__(data={'count': len(self)})
return super(ElementCollection, self).__repr__(
data={'count': len(self)})


class XyzCollection(BaseObject):
"""
Expand Down
12 changes: 12 additions & 0 deletions rpw/ui/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ def clear(self):
ElementSet.clear(self)
self.update()

def __getitem__(self, index):
"""
Overrides ElementSet __getitem__ to retrieve from selection
based on index.
"""
# https://github.com/gtalarico/revitpythonwrapper/issues/32
for n, element in enumerate(self.__iter__()):
if n ==index:
return element
else:
raise IndexError('Index is out of range')

def __bool__(self):
"""
Returns:
Expand Down

0 comments on commit 2753562

Please sign in to comment.