示例#1
0
 def recurse_change_filter(self, filter):
     """Рекурсивное изменение текстовых фильтров."""
     if isinstance(filter, LogicalAndFilter):
         res = LogicalAndFilter(
             self.recurse_change_filter(filter.GetFilters()))
         return res
     elif isinstance(filter, LogicalOrFilter):
         res = LogicalOrFilter(
             self.recurse_change_filter(filter.GetFilters()))
         return res
     elif isinstance(filter, ElementParameterFilter):
         arr = List[FilterRule]()
         for i in filter.GetRules():
             if isinstance(i, FilterInverseRule):
                 i = i.GetInnerRule()
                 cur_kit = self.cur_rule(i.RuleString)
                 i.RuleString = cur_kit
                 i = FilterInverseRule(i)
             if isinstance(i, FilterStringRule):
                 cur_kit = self.cur_rule(i.RuleString)
                 i.RuleString = cur_kit
             arr.Add(i)
         res = ElementParameterFilter(arr)
         return res
     elif isinstance(filter, List[ElementFilter]):
         arr = List[ElementFilter]()
         for i in filter:
             arr.Add(self.recurse_change_filter(i))
         return arr
示例#2
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
示例#3
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)
示例#4
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()
def get_rules(s):
    result = []
    for part in s.split('; ')[1:]:
        param_name = part.split('"')[2]
        value = part.split('"')[4]
        evaluator = pars.replace(' "' + param_name + '"',
                                 '').replace(' "' + value + '"', '').split()[1]
        param = get_param(param_name)
        rule = create_rule(param, evaluator, value)
        result.append(rule)
    return result

    pfilter = parameterFilterElement = ParameterFilterElement.Create(
        doc, name + ' не', cats,
        ElementParameterFilter(
            ParameterFilterRuleFactory.CreateNotEqualsRule(
                ElementId(BuiltInParameter.RBS_SYSTEM_NAME_PARAM), name,
                True)))
示例#6
0
文件: script.py 项目: Melca-G/Aeolus
    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
paramFilters = ElementParameterFilter(fRules)
ele = filter.WherePasses(paramFilters).ToElements()
elements = []
for i in ele:
    elements.append(i)

# Task Dialogue Creation
dialog = TaskDialog('Warning')
dialog.CommonButtons = TaskDialogCommonButtons.Ok
dialog.DefaultButton = TaskDialogResult.Ok
dialog.Title = 'Warning'
dialog.MainInstruction = 'You are about to select ' + str(
    len(elements)) + ' elements'
bool = dialog.Show()
if str(bool) == 'Ok':
    revit.get_selection().set_to(elements)
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)

# adapted with kudos to archilab getRoomsByLevel
# https://gist.github.com/ksobon/8007f64a889df00afd22#file-getroomsbylevel-py

# unwrap the level selected from the dynamo node
levelUnwrapped = UnwrapElement(levelInput)
# get the Id of the level
levelUnwrappedId = levelUnwrapped.Id
# filter elements by the unwrapped level id
levelFilter = ElementLevelFilter(levelUnwrappedId)

# alias areaFilter, for areas (not rooms) we will want to exclude
areaFilter = AreaFilter()
# change to room filter if you want svg of areas not rooms
#areaFilter = RoomFilter()
示例#8
0
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

# Does the mark string contain the test value 'M.'
test = 'begins'

# booleon (True/False) controls if test is case sensitive
caseSensitive = False

# we run a Filter String Rule that checks the chosen parameter
# 'ALL_MODEL_MARK' runs against the evaluator (does this string)
# contain  our test string value 'M.'
# refer to api docs for details of the FilterStringRule Constructor
# http://www.revitapidocs.com/2015/056fd8e1-a989-b262-8c8e-9e79ece62b01.htm
rule = FilterStringRule(provider, evaluator, test, caseSensitive)

# generate a filter based off our Rule
filter = ElementParameterFilter(rule)

# Now we have a valid rule to run against our Filtered Element Collector.
# # So in this case we pull everything inside the document
# but only if it passes our filter test
# then make sure we return the elements themselves with '.ToElements()'
analyticalCollector = fec(doc).WherePasses(filter).ToElements()

# To get our results back inside of Dynamo
# we need to append a list to the OUT port
OUT = analyticalCollector
示例#9
0
            new_logic = src_f_logic[line_no]
            logic_mod = True if new_logic != current_logic else False
            current_logic = new_logic if new_logic != current_logic else current_logic
            new_rules = src_f_rules[line_no]
            rules_mod = True if new_rules != current_rules else False
            current_rules = new_rules if new_rules != current_rules else current_rules
            if name_mod:
                filt.Name = current_name
                status.append('n')
            if cats_mod:
                filt.SetCategories(List[ElementId](get_cats(current_cats)))
                status.append('c')
            if rules_mod or logic_mod:
                rules = get_rules(current_rules) if current_rules else []
                epfilters = [
                    ElementParameterFilter(rule) for rule in rules
                ]  # не протестирован и не проработан вариант создания фильтра без правил
                lfilter = LogicalAndFilter(
                    epfilters) if current_logic == 'And' else LogicalOrFilter(
                        epfilters)
                filt.SetElementFilter(lfilter)
                status.append('r')
    status = 'Mod ' + ', '.join(status) if status else ''

    data.append([
        current_id, current_name, current_cats, current_logic, current_rules,
        status
    ])

if src_filters:
    all_filter_ids = [str(i.Id) for i in all_filters]