Ejemplo n.º 1
0
def create_modifier_filters(exclude=False):
    """Create standard rule-based filters for available tag modifiers.

    Args:
        exclude (bool, optional): create exclusion filter, defaults to False

    Returns:
        list[DB.ParameterFilterElement]: list of created filters
    """
    mfilters = []

    existing_filters = [x for x in revit.query.get_rule_filters()]

    for modif in TagModifiers.get_modifiers():
        # create filter name and check availability
        filter_name = \
            '{} {}'.format('NONE' if exclude else 'ALL', modif.name)
        filter_exists = False
        for exst_filter in existing_filters:
            if exst_filter.Name == filter_name:
                filter_exists = True
                mfilters.append(exst_filter)
        if filter_exists:
            continue

        # get tags param id
        param_id = _get_tag_paramid()

        # create filter rule
        rules = framework.List[DB.FilterRule]()
        param_prov = DB.ParameterValueProvider(param_id)
        param_contains = DB.FilterStringContains()
        rule = DB.FilterStringRule(param_prov,
                                   param_contains,
                                   modif.tag,
                                   False)
        if exclude:
            rule = DB.FilterInverseRule(rule)
        rules.Add(rule)

        # collect applicable categories
        cats = []
        for cat in revit.query.get_all_category_set():
            if DB.ParameterFilterElement.AllRuleParametersApplicable(
                    revit.doc,
                    framework.List[DB.ElementId]([cat.Id]),
                    rules
                ):
                cats.append(cat.Id)

        # create filter
        mfilter = DB.ParameterFilterElement.Create(
            revit.doc,
            filter_name,
            framework.List[DB.ElementId](cats),
            rules
            )
        mfilters.append(mfilter)
    return mfilters
Ejemplo n.º 2
0
forms.check_viewtype(threeD_view, DB.ViewType.ThreeD, exitscript=True)
viewTypeId = threeD_view.GetTypeId()

today = date.today()
today = today.strftime("%m/%d/%Y")

with forms.WarningBar(title="Pick source object:"):
    source_elements = revit.pick_elements()

values = []
if source_elements:

    # Get all SSG Families
    mfg_param_id = DB.ElementId(DB.BuiltInParameter.ALL_MODEL_MANUFACTURER)
    mfg_param_prov = DB.ParameterValueProvider(mfg_param_id)
    param_contains = DB.FilterStringContains()
    mfg_value_rule = DB.FilterStringRule(mfg_param_prov, param_contains,
                                         "Southwest Solutions Group", False)
    param_filter = DB.ElementParameterFilter(mfg_value_rule)
    ssg_fams = (DB.FilteredElementCollector(revit.doc).WherePasses(
        param_filter).WhereElementIsNotElementType().ToElements())

    # Get the secondary titleblock
    title_blocks = (DB.FilteredElementCollector(revit.doc).OfCategory(
        DB.BuiltInCategory.OST_TitleBlocks).WhereElementIsElementType())
    pdf_tb = [
        t for t in title_blocks
        if t.FamilyName + ": " + t.LookupParameter("Type Name").AsString() ==
        "SSG_TB_8.5x11_PDF: Primary"
    ][0]
    pdf_tb_2 = [
Ejemplo n.º 3
0
def create_tag_filter(tags, name_format=None, exclude=False):
    """Create standard rule-based filters for given tags (max of 3 tags).

    Args:
        tags (list[Tag]): list of tags to create filter for (max of 3)
        name_format (str, optional): format for naming the filter,
            must include `{all_or_none}` and `{tag_names}`.
        exclude (bool, optional): create exclusion filter, defaults to False

    Returns:
        list[DB.ParameterFilterElement]: list of created filters

    Example:
        >>> import tagsmgr
        >>> fname = 'CUSTOM {all_or_none} FILTER FOR {tag_names}'
        >>> tag_filters = tagmgr.create_tag_filter(tags,
        ...                                              name_format=fname,
        ...                                              exclude=True)
        [<Autodesk.Revit.DB.ParameterFilterElement object at ...>,
        <Autodesk.Revit.DB.ParameterFilterElement object at ...>]
    """
    sfilters = []
    # create filter name and check availability
    tags_col = join_tags(tags)
    if not name_format:
        name_format = tagscfg.TAG_FILTER_NAMING
    filter_name = name_format.format(all_or_none='NONE' if exclude else 'ALL',
                                     tag_names=tags_col.names)
    for exst_filter in revit.query.get_rule_filters():
        if exst_filter.Name == filter_name:
            sfilters.append(exst_filter)
            return sfilters

    # get tags param id
    param_id = _get_tag_paramid()

    # create filter rule
    if HOST_APP.is_newer_than(2019, or_equal=True):
        rules = None
    else:
        rules = framework.List[DB.FilterRule]()
    param_prov = DB.ParameterValueProvider(param_id)
    param_contains = DB.FilterStringContains()
    for tag in tags:
        rule = DB.FilterStringRule(param_prov,
                                   param_contains,
                                   tag.name,
                                   False)
        if exclude:
            rule = DB.FilterInverseRule(rule)

        if HOST_APP.is_newer_than(2019, or_equal=True):
            if rules:
                rules = DB.LogicalOrFilter(rules,
                                           DB.ElementParameterFilter(rule))
            else:
                rules = DB.ElementParameterFilter(rule)
        else:
            rules.Add(rule)

    # collect applicable categories
    cats = []
    for cat in revit.query.get_all_category_set():
        if DB.ParameterFilterElement.AllRuleParametersApplicable(
                revit.doc,
                framework.List[DB.ElementId]([cat.Id]),
                rules
            ):
            cats.append(cat.Id)

    # create filter
    sfilter = \
        DB.ParameterFilterElement.Create(revit.doc,
                                         filter_name,
                                         framework.List[DB.ElementId](cats),
                                         rules)
    sfilters.append(sfilter)
    return sfilters