Beispiel #1
0
def create_filter(key_parameter, element_value):
    """Function to create a RevitAPI filter."""
    f_parameter = ParameterValueProvider(ElementId(key_parameter))
    f_parameter_value = element_value  #e.g. element.Category.Id
    f_rule = FilterElementIdRule(f_parameter, FilterNumericEquals(),
                                 f_parameter_value)
    filter = ElementParameterFilter(f_rule)
    return filter
Beispiel #2
0
def create_string_equals_filter(key_parameter,
                                element_value,
                                caseSensitive=True):
    """Function to create ElementParameterFilter based on FilterStringRule."""
    f_parameter = ParameterValueProvider(ElementId(key_parameter))
    f_parameter_value = element_value
    caseSensitive = True
    f_rule = FilterStringRule(f_parameter, FilterStringEquals(),
                              f_parameter_value, caseSensitive)
    return ElementParameterFilter(f_rule)
Beispiel #3
0
def create_filter(key_parameter, element_value):
    """Function to create a RevitAPI filter."""
    f_parameter = ParameterValueProvider(ElementId(key_parameter))
    f_parameter_value = element_value  # e.g. element.Category.Id
    f_rule = FilterElementIdRule(f_parameter, FilterNumericEquals(),
                                 f_parameter_value)
    filter = ElementParameterFilter(f_rule)
    return filter


# EXAMPLE GET GROUP INSTANCE
# filter = create_filter(BuiltInParameter.ELEM_TYPE_PARAM, group_type_id)
# group = FilteredElementCollector(doc).WherePasses(filter).FirstElement()
Beispiel #4
0
        Selection.get_all_parameters_as_dic(selection[0])[i].Id)
for i in sel_param_strings:
    sel_params.append(Selection.get_all_parameters_as_dic(selection[0])[i])
# process parameters into names and string values
names = []
values = []
for i in sel_param_strings:
    a = re.split(': ', str(i))
    names.append(a[0])
    values.append(a[1])
count = 0
filter = FilteredElementCollector(doc)
fRules = []
# create parameter filter by data type
for i in sel_params:
    pvp = ParameterValueProvider(sel_param_ids[count])
    if 'String' in str(i.StorageType):
        fnrv = FilterStringEquals()
        fRule = FilterStringRule(pvp, fnrv, values[count], True)
    elif 'Interger' in str(i.StorageType):
        fnrv = FilterNumericEquals()
        fRule = FilterIntegerRule(pvp, fnrv, int(values[count]))
    elif 'Double' in str(i.StorageType):
        fnrv = FilterNumericEquals()
        fRule = FilterDoubleRule(pvp, fnrv, float(values[count]), 0.001)
    elif 'ElementId' in str(i.StorageType):
        fnrv = FilterNumericEquals()
        fRule = FilterElementIdRule(pvp, fnrv, ElementId(int(values[count])))
    fRules.append(fRule)
    count += 1
# Filter all elements based on parameter values selected
Beispiel #5
0
def parameter_value_provider(base_class, built_in_parameter):
    # type: (type, str) -> ParameterValueProvider
    element = FilteredElementCollector(doc).OfClass(base_class).FirstElement()
    system_type_parameter_id = element.get_Parameter(built_in_parameter).Id
    return ParameterValueProvider(system_type_parameter_id)
# -----------------------

# if there are any rooms that are deleted / unplaced or otherwise
# unbounded, eg there are two rooms in a single room boundary
# they will have a room area of 0.0 and need to be filtered out
# the following filter 'filterArea0' will return rooms with an area
# greater than 0.000, eg 0.001 or greater

# built in parameter names allow us to refer to parameter names without
# having to worry about if the parameter name dispalyed in revit is in
# english, french, or another language, as it will always be the same
# refer to apidocs.com for a full list of built in parameter enumeration
# http://www.revitapidocs.com/2018.1/fb011c91-be7e-f737-28c7-3f1e1917a0e0.htm
paramArea0 = BuiltInParameter.ROOM_AREA
# provide elements to be tested by element id
providerArea0 = ParameterValueProvider(ElementId(paramArea0))
# evaulate for values greater than test value
evaluatorGr = FilterNumericGreater()
# conversion factor for square meters to square feet
sqMToSqFt = 10.7639
# because the revit API considers values in square feet we need to use
# a conversion factor to change to square meters, this is not strictly
# necessary if tested against zero, but useful to understand.
testArea0 = 0.0 * sqMToSqFt
# precision of rounding used to evaulate rule is not strictly necessary
# if tested against zero, but included so can be adapted to other values
epsilon = 10**-3
# use rule for doubles
ruleArea0 = FilterDoubleRule(providerArea0, evaluatorGr, testArea0, epsilon)
# filter with rule
filterArea0 = ElementParameterFilter(ruleArea0)
Beispiel #7
0
# which allows us to simply call 'doc' later without
# having to type the long namespace name
doc = DocumentManager.Instance.CurrentDBDocument
# similary FilteredElementCollector is shortened to fec
fec = FilteredElementCollector

# Here we use the Built In Parameter method to choose the string parameter
# of 'ALL_MODEL_MARK' across all Elements inside of the Revit Document
# refer to api docs for all built in parameter enumarations
# http://www.revitapidocs.com/2018.1/fb011c91-be7e-f737-28c7-3f1e1917a0e0.htm
param = BuiltInParameter.ALL_MODEL_MARK

# Once we have our BuiltInParameter, we need to get it's Element Id
# and convert it to a Parameter Value Provider
# in order to use it inside of our filter
provider = ParameterValueProvider(ElementId(param))

# refer to api docs for available evaulators
# http://www.revitapidocs.com/2016/b317951e-6324-fc45-5860-6b616534d1ce.htm?query=filter%20string%20class
evalBegins = FilterStringBeginsWith()
evalCon = FilterStringContains()
evalEnds = FilterStringEndsWith()
evalEq = FilterStringEquals()
evalGreat = FilterStringGreater()
evalGoEq = FilterStringGreaterOrEqual()
evalLess = FilterStringLess()
evalLoEq = FilterStringLessOrEqual()
# Here we select which evaluator will be used to test against a set value
# whilst maintaining the list of other filters for reference
evaluator = evalBegins