Model > Select

Filter Selection

Keeps or removes the selected items whose property passes a test (equals, contains, greater than, is missing...) without running a new search.

Tab and panelModel > Select
KindButton
Live whenSomething is selected

Status

Untested Never executed inside Navisworks. Passed the headless checks only.

The public ask

No public source is on record for this tool.

Events it listens to

None. It runs only when you click it.

Files

Paths are relative to the Playground.extension folder.

  • Model.tab/Select.panel/Filter_Selection.pushbutton/bundle.yaml
  • Model.tab/Select.panel/Filter_Selection.pushbutton/icon.dark.png
  • Model.tab/Select.panel/Filter_Selection.pushbutton/icon.png
  • Model.tab/Select.panel/Filter_Selection.pushbutton/icon.small.dark.png
  • Model.tab/Select.panel/Filter_Selection.pushbutton/icon.small.png
  • Model.tab/Select.panel/Filter_Selection.pushbutton/script.py

Install

  1. Only this tool. In Navisworks, click pyNavis > Playground, search for Filter Selection, tick it and click Install.
  2. The whole extension. Download Playground.extension.zip, unzip it, put the Playground.extension folder in %APPDATA%\pyNavis\extensions\, and click pyNavis > Reload. Filter Selection is on the Model tab, Select panel.

You need pyNavis 1.3.0 or later.

Tried it? Tell us whether it worked or not. That report is what moves a tool up the status ladder.

Report

Source

The tool's own files, word for word as published in pynavis/Playground. Paths are relative to the Playground.extension folder.

script.py

The script that runs on a click.

Model.tab/Select.panel/Filter_Selection.pushbutton/script.py View on GitHub
# -*- coding: utf-8 -*-
"""Keeps or removes the selected items whose property passes a test, without a new search."""
from pynavis import script, toast

from namo import find_query, items, progress, rules, selecttools, ui

cfg = script.get_config(selecttools.FILTER_DEFAULTS)
selected = items.selected()


def ask_property():
    rows = [{'value': (c, p), 'cells': [c, p, n]} for c, p, n in selecttools.property_rows(selected)]
    if not rows:
        toast.info('Nothing to test', 'The selected items carry no properties.')
        return None
    picked = ui.choose('Filter Selection', rows, ['Category', 'Property', 'Sampled items carrying it'],
                       multiselect=False, checked=[(cfg['category'], cfg['property'])],
                       prompt='Choose the property to test. Listed from the first 200 selected '
                              'items and their elements.', width=660)
    return None if picked is None else picked[0]


def ask_test(category, prop):
    sample = selected[:2000]
    observed = [find_query.read(item, category, prop, True)[1] for item in sample]
    tally = find_query.tally_values([v for v in observed if v is not None])
    options = selecttools.value_options(tally)
    needs = [op for op, _label, need in rules.OPS if need]

    def validate(values):
        if values['op'] in needs and values['value'] == selecttools.OTHER and \
                not values['typed'].strip():
            return {'typed': 'Type the value to compare with.'}
        return None
    fields = [
        {'kind': 'label', 'text': '%s > %s, tested on %s selected items.' % (
            category, prop, '{:,}'.format(len(selected)))},
        {'kind': 'choice', 'key': 'op', 'label': 'Test',
         'options': [(label, op) for op, label in selecttools.filter_ops()], 'default': cfg['op'], 'fallback': None},
        {'kind': 'choice', 'key': 'value', 'label': 'Value', 'options': options,
         'default': options[0][1], 'enabled_if': ('op', needs),
         'hint': 'Values seen on the first %s items, most common first.' % '{:,}'.format(len(sample))},
        {'kind': 'text', 'key': 'typed', 'label': 'Typed value',
         'enabled_if': ('value', selecttools.OTHER),
         'hint': 'For between type 1 and 3; for is one of, separate values with commas.'},
        {'kind': 'radio', 'key': 'mode', 'label': 'Items that pass',
         'options': [('Keep them', 'keep'), ('Remove them', 'remove')], 'inline': True,
         'default': cfg['mode'], 'fallback': None},
        {'kind': 'check', 'key': 'use_object', 'default': cfg['use_object'],
         'label': "Test the element's properties when an item has none of its own"},
    ]
    answer = ui.form('Filter Selection', fields, ok='Filter', validate=validate, width=500)
    if answer is None:
        return None
    return answer, selecttools.picked_condition(category, prop, answer['op'], answer['value'],
                                               answer['typed'], tally)


if not selected:
    toast.info('Nothing selected', 'Select the items to filter first.')
else:
    picked = ask_property()
    if picked is not None:
        category, prop = picked
        asked = ask_test(category, prop)
        if asked is not None:
            answer, cond = asked
            keep = answer['mode'] == 'keep'
            script.save_config({'category': category, 'property': prop, 'op': answer['op'],
                                'mode': answer['mode'], 'use_object': answer['use_object']})
            if len(selected) > selecttools.FILTER_PROGRESS_OVER:
                kept = progress.run('Filtering the selection', lambda report: selecttools.run_filter(
                    selected, cond, keep, answer['use_object'], report))
            else:
                kept = selecttools.run_filter(selected, cond, keep, answer['use_object'])
            if kept is not progress.CANCELLED:
                level, message, detail = selecttools.filter_summary(
                    len(kept), len(selected), keep, rules.describe(cond))
                if 0 < len(kept) < len(selected):
                    items.select(kept)
                toast.show(level, message, detail)

Library modules this tool uses

From the shared namo library, which installs with every tool. Each name opens the module on GitHub.

  • namo.find_queryNative search conditions built from property values, shared by the Select and Find tools.
  • namo.itemsModel items: walking, collecting, identifying, measuring and showing them.
  • namo.progressGlue between pyNavis' cancellable progress window and Playground's progress callbacks.
  • namo.rulesOne condition engine for every rule-driven Playground tool.
  • namo.selecttoolsSelect panel logic: Select Similar, Filter Selection, Invert, Select by File, Save as Set.
  • namo.uiWPF building blocks for Playground tools, themed from the pyNavis design system.

bundle.yaml

The bundle contract: the keys pyNavis reads for this tool.

Model.tab/Select.panel/Filter_Selection.pushbutton/bundle.yaml View on GitHub
title: Filter\nSelection
tooltip: Keeps or removes the selected items whose property passes a test (equals, contains, greater than, is missing...) without running a new search.
context: selection