Model > Data

Property Labels

Draws a chosen property's value above each selected object in the view, on a short leader from the top of its box (up to 500 objects). Labels follow orbit and zoom; Clear Labels removes them.

Tab and panelModel > Data
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/Data.panel/Property_Labels.pushbutton/bundle.yaml
  • Model.tab/Data.panel/Property_Labels.pushbutton/icon.dark.png
  • Model.tab/Data.panel/Property_Labels.pushbutton/icon.png
  • Model.tab/Data.panel/Property_Labels.pushbutton/icon.small.dark.png
  • Model.tab/Data.panel/Property_Labels.pushbutton/icon.small.png
  • Model.tab/Data.panel/Property_Labels.pushbutton/script.py

Install

  1. Only this tool. In Navisworks, click pyNavis > Playground, search for Property Labels, 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. Property Labels is on the Model tab, Data 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/Data.panel/Property_Labels.pushbutton/script.py View on GitHub
# -*- coding: utf-8 -*-
"""Labels each selected object in the view with the value of a chosen property."""
from pynavis import script, toast

from namo import data_common, data_labels, items, propindex, ui

DEFAULTS = {'property': 'Item > Name'}


def run():
    if ui.is_runner():
        toast.info('Property Labels needs the Navisworks window', 'It cannot open under pynavis run.')
        return
    doc = data_common.active_doc()
    selected = items.selected(doc) if data_common.has_models(doc) else []
    if not selected:
        toast.info('Nothing selected', 'Select the objects to label, then run Property Labels again.')
        return
    values = script.get_config(DEFAULTS)
    choices = propindex.property_choices(doc, scope='selection')
    rows = [{'cells': [c, p, n], 'value': propindex.pair_text(c, p)} for c, p, n in choices]
    if not rows:
        toast.info('No properties on the selection', 'Select objects that carry properties.')
        return
    picked = ui.choose('Property Labels', rows, ['Tab', 'Property', 'Items seen'], multiselect=False,
                       checked=[values.get('property')], prompt='Label each selected object with which value?',
                       ok='Label')
    if picked is None:
        return
    script.save_config({'property': picked[0]})
    category, prop = propindex.split_pair(picked[0])
    # One label per element. The value is read from the element, then from the item
    # as selected (a geometry part can carry a property its element does not).
    objects = []
    picked_as = {}
    for item in selected:
        obj = items.object_of(item)
        if obj not in picked_as:
            picked_as[obj] = item
            objects.append(obj)
    capped = len(objects) > data_labels.MAX_LABELS
    reader = propindex.Reader(doc)
    labels = []
    without = 0
    for obj in objects[:data_labels.MAX_LABELS]:
        text = reader.text(obj, category, prop)
        if text == propindex.MISSING:
            text = reader.text(picked_as[obj], category, prop)
        if text in (propindex.MISSING, propindex.NO_VALUE):
            without += 1
            continue
        box = items.bbox(obj)
        if box is None:
            without += 1
            continue
        labels.append((box, text))
    if not labels:
        toast.info('Nothing to label', 'None of the selected objects has a value for %s.' % picked[0])
        return
    drawn, loaded = data_labels.draw(labels, doc)
    if not loaded:
        toast.warning('Labels could not be drawn',
                      'The pyNavis view overlay is not loaded. Restart Navisworks, then try again.')
        return
    notes = ['Clear Labels removes them.']
    if without:
        notes.insert(0, '%s without a value.' % '{:,}'.format(without))
    if capped:
        notes.insert(0, 'First %s of %s objects.' % ('{:,}'.format(data_labels.MAX_LABELS),
                                                     '{:,}'.format(len(objects))))
    level = toast.warning if capped else toast.success
    level('Labelled %s %s with %s' % ('{:,}'.format(drawn), 'object' if drawn == 1 else 'objects', prop),
          ' '.join(notes))


run()

Library modules this tool uses

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

  • namo.data_commonShared plumbing for the Inspect and Data panel tools: progress stages, where files go by default, the scope dialog fields, and the small checks every button starts with.
  • namo.data_labelsProperty Labels: a property's value drawn above each selected object in the 3D view through pynavis.overlay, with a short leader from the object's top-centre.
  • namo.itemsModel items: walking, collecting, identifying, measuring and showing them.
  • namo.propindexProperty scanning shared by Property Explorer, Count by Property, Data Validator and the Write Data tools: scopes, fast value reading, the category > property > value index.
  • 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/Data.panel/Property_Labels.pushbutton/bundle.yaml View on GitHub
title: Property\nLabels
tooltip: Draws a chosen property's value above each selected object in the view, on a short leader from the top of its box (up to 500 objects). Labels follow orbit and zoom; Clear Labels removes them.
context: selection