revitron.filter¶
The filter
submodule is one of the most essential one within the Revitron package.
Its main purpose is taking over the heavy lifting of filtering elements in the Revit database and
complementing the standard Revit API FilteredElementCollector
class with
the ability to filter collections by parameter values:
elements = (
revitron.Filter
.byStringEquals('param', 'value')
.noTypes()
.getElements()
)
Note that you can invert a filter by providing a the third argument for a string filter as follows:
elements = (
revitron.Filter
.byStringEquals('param', 'value', True)
.noTypes()
.getElements()
)
Note
In order to filter elements in another model instead of the active one, it is possible to change
the document context using the with
statement.
The document context can be changed as follows:
with revitron.Document(anyOtherDoc):
fltr = revitron.Filter().noTypes()
elements = fltr.getElements()
Classes:
|
A filter class based on the |
- class Filter(scope=None)[source]¶
Bases:
object
A filter class based on the
FilteredElementCollector
class.Methods:
__init__
([scope])Inits a new Filter instance.
byCategory
(name)Filters the collection by a category name or a built-in category name.
byClass
(cls)Filters the collection by class.
byIntersection
(element)Reduces the set of elements to the ones that are intersecting a given element.
byNumberIsEqual
(paramName, value[, invert])Filters the collection by parameter values equal to a given number.
byNumberIsGreater
(paramName, value[, invert])Filters the collection by parameter values greater than a given number.
byNumberIsGreaterOrEqual
(paramName, value[, ...])Filters the collection by parameter values greater than or equal to a given number.
byNumberIsLess
(paramName, value[, invert])Filters the collection by parameter values smaller than a given number.
byNumberIsLessOrEqual
(paramName, value[, invert])Filters the collection by parameter values smaller than or equal to a given number.
byOneInCsv
(evaluatorName, paramName, csv[, ...])Filters the collection by testing whether a string contains at lease one ot the items in a CSV list.
byRegex
(paramName, regex[, invert])Filters a collection by a given regex.
byStringBeginsWith
(paramName, value[, invert])Filters the collection by a string at the beginning of a parameter value.
byStringContains
(paramName, value[, invert])Filters the collection by a string contained in a parameter.
byStringContainsOneInCsv
(paramName, csv[, ...])Filters the collection by testing whether a string contains at lease one ot the items in a CSV list.
byStringEndsWith
(paramName, value[, invert])Filters the collection by a string at the end of a parameter.
byStringEquals
(paramName, value[, invert])Filters the collection by a string that equals a parameter value.
byStringEqualsOneInCsv
(paramName, csv[, invert])Filters the collection by testing whether a string equals at lease one ot the items in a CSV list.
Get the collection as element IDs.
Get the collection as elements.
noTypes
()Removes all types from collection.
Reduce to collection to types only.
- __init__(scope=None)[source]¶
Inits a new Filter instance.
- Parameters
scope (Element ID or list of elements, optional) – The optional scope. It can be either a view Id or a list of elements. Defaults to None.
- byCategory(name)[source]¶
Filters the collection by a category name or a built-in category name.
Note that there are basically three valid types that can be used as the filter argument. The first two use the name of a built-in category (with or without the
OST_
prefix):fltr = revitron.Filter().byCategory('Walls') fltr = revitron.Filter().byCategory('OST_Walls')
The third type uses a natural category name to find a corresponding built-in category to filter, here
OST_BeamAnalyticalTags
:fltr = revitron.Filter().byCategory('Analytical Beam Tags')
- Parameters
name (string) – A category or built-in category name
- Returns
The Filter instance
- Return type
object
- byClass(cls)[source]¶
Filters the collection by class.
Example:
fltr = revitron.Filter() cls = Autodesk.Revit.DB.CurveElement ids = fltr.byClass(cls).noTypes().getElementIds()
Alternatively it is also possible to use a class name as string instead:
fltr = revitron.Filter() ids = fltr.byClass('CurveElement').noTypes().getElementIds()
- Parameters
cls (class) – A class or class name to filter the elements
- Returns
The Filter instance
- Return type
object
- byIntersection(element)[source]¶
Reduces the set of elements to the ones that are intersecting a given element.
- Parameters
element (objetc) – A Revit element
- Returns
The Filter instance
- Return type
object
- byNumberIsEqual(paramName, value, invert=False)[source]¶
Filters the collection by parameter values equal to a given number.
Example:
fltr = revitron.Filter() ids = fltr.byNumberIsEqual('Area', 5).noTypes().getElementIds()
- Parameters
paramName (string) – The parameter name
value (number) – The numeric value to compare to
invert (boolean) – Inverts the filter
- Returns
The collector
- Return type
object
- byNumberIsGreater(paramName, value, invert=False)[source]¶
Filters the collection by parameter values greater than a given number.
Example:
fltr = revitron.Filter() ids = fltr.byNumberIsGreater('Area', 5).noTypes().getElementIds()
- Parameters
paramName (string) – The parameter name
value (number) – The numeric value to compare to
invert (boolean) – Inverts the filter
- Returns
The collector
- Return type
object
- byNumberIsGreaterOrEqual(paramName, value, invert=False)[source]¶
Filters the collection by parameter values greater than or equal to a given number.
Example:
fltr = revitron.Filter() fltr = fltr.byNumberIsGreaterOrEqual('Area', 5).noTypes() ids = fltr.getElementIds()
- Parameters
paramName (string) – The parameter name
value (number) – The numeric value to compare to
invert (boolean) – Inverts the filter
- Returns
The collector
- Return type
object
- byNumberIsLess(paramName, value, invert=False)[source]¶
Filters the collection by parameter values smaller than a given number.
Example:
fltr = revitron.Filter() ids = fltr.byNumberIsLess('Area', 5).noTypes().getElementIds()
- Parameters
paramName (string) – The parameter name
value (number) – The numeric value to compare to
invert (boolean) – Inverts the filter
- Returns
The collector
- Return type
object
- byNumberIsLessOrEqual(paramName, value, invert=False)[source]¶
Filters the collection by parameter values smaller than or equal to a given number.
Example:
fltr = revitron.Filter() ids = fltr.byNumberIsLessOrEqual('Area', 5).noTypes().getElementIds()
- Parameters
paramName (string) – The parameter name
value (number) – The numeric value to compare to
invert (boolean) – Inverts the filter
- Returns
The collector
- Return type
object
- byOneInCsv(evaluatorName, paramName, csv, invert=False)[source]¶
Filters the collection by testing whether a string contains at lease one ot the items in a CSV list.
This method is the base method for the
byStringContainsOneInCsv
andbyStringEqualsOneInCsv
methods.Note
that by setting
invert
toTrue
, all elements that match one of the items will be removed from the collection.- Parameters
evaluatorName (method) – The filter method to be used to filter
paramName (string) – The name of the parameter
csv (string) – A comma separated list of items
invert (bool, optional) – Inverts the filter. Defaults to False.
- Returns
The Filter instance
- Return type
object
- byRegex(paramName, regex, invert=False)[source]¶
Filters a collection by a given regex.
- Parameters
paramName (string) – The name of the parameter to be matched.
regex (string) – The regex.
invert (bool, optional) – Inverts the filter. Defaults to False.
- Returns
The Filter instance
- Return type
object
- byStringBeginsWith(paramName, value, invert=False)[source]¶
Filters the collection by a string at the beginning of a parameter value.
Example:
fltr = revitron.Filter() fltr = fltr.byStringBeginsWith('param', 'value').noTypes() ids = fltr.getElementIds()
- Parameters
paramName (string) – The parameter name
value (string) – The searched string
invert (boolean) – Inverts the filter
- Returns
The collector
- Return type
object
- byStringContains(paramName, value, invert=False)[source]¶
Filters the collection by a string contained in a parameter.
Example:
fltr = revitron.Filter() fltr = fltr.byStringContains('param', 'value').noTypes() ids = fltr.getElementIds()
- Parameters
paramName (string) – The parameter name
value (string) – The searched string
invert (boolean) – Inverts the filter
- Returns
The collector
- Return type
object
- byStringContainsOneInCsv(paramName, csv, invert=False)[source]¶
Filters the collection by testing whether a string contains at lease one ot the items in a CSV list.
Note
that by setting
invert
toTrue
, all elements that match one of the items will be removed from the collection.Example:
fltr = revitron.Filter() fltr = fltr.byStringContainsOneInCsv('Family', 'some, words', False) fltr = fltr.noTypes() elements = fltr.getElements()
- Parameters
paramName (string) – The name of the parameter
csv (string) – A comma separated list of items
invert (bool, optional) – Inverts the filter. Defaults to False.
- Returns
The Filter instance
- Return type
object
- byStringEndsWith(paramName, value, invert=False)[source]¶
Filters the collection by a string at the end of a parameter.
- Parameters
paramName (string) – The parameter name
value (string) – The searched string
invert (boolean) – Inverts the filter
- Returns
The collector
- Return type
object
- byStringEquals(paramName, value, invert=False)[source]¶
Filters the collection by a string that equals a parameter value.
Example:
fltr = revitron.Filter() ids = fltr.byStringEquals('param', 'value').noTypes().getElementIds()
- Parameters
paramName (string) – The parameter name
value (string) – The searched string
invert (boolean) – Inverts the filter
- Returns
The collector
- Return type
object
- byStringEqualsOneInCsv(paramName, csv, invert=False)[source]¶
Filters the collection by testing whether a string equals at lease one ot the items in a CSV list.
Note
that by setting
invert
toTrue
, all elements that match one of the items will be removed from the collection.Example:
fltr = revitron.Filter() fltr = fltr.byStringEqualsOneInCsv('Family', 'some, words', False) fltr = fltr.noTypes() elements = fltr.getElements()
- Parameters
paramName (string) – The name of the parameter
csv (string) – A comma separated list of items
invert (bool, optional) – Inverts the filter. Defaults to False.
- Returns
The Filter instance
- Return type
object
- getElementIds()[source]¶
Get the collection as element IDs.
- Returns
The list of excluded element IDs
- Return type
list
- getElements()[source]¶
Get the collection as elements.
- Returns
The list of excluded elements
- Return type
list