Model > Look
Legend Maker
Draws the last color scheme as a print-ready PNG legend with swatches and counts, and can save a viewpoint that brings those colors back.
Status
Untested Never executed inside Navisworks. Passed the headless checks only.
The public ask
No public source is on record for this tool.
Installs with
Legend Maker sits in a stack, so installing it also installs:
Events it listens to
None. It runs only when you click it.
Files
Paths are relative to the Playground.extension folder.
Model.tab/Look.panel/Look_Tools.stack/Legend_Maker.pushbutton/bundle.yamlModel.tab/Look.panel/Look_Tools.stack/Legend_Maker.pushbutton/icon.dark.pngModel.tab/Look.panel/Look_Tools.stack/Legend_Maker.pushbutton/icon.pngModel.tab/Look.panel/Look_Tools.stack/Legend_Maker.pushbutton/icon.small.dark.pngModel.tab/Look.panel/Look_Tools.stack/Legend_Maker.pushbutton/icon.small.pngModel.tab/Look.panel/Look_Tools.stack/Legend_Maker.pushbutton/script.py
Install
- Only this tool. In Navisworks, click pyNavis > Playground, search for Legend Maker, tick it and click Install.
- The whole extension. Download
Playground.extension.zip, unzip it, put thePlayground.extensionfolder in%APPDATA%\pyNavis\extensions\, and click pyNavis > Reload. Legend Maker is on the Model tab, Look 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.
ReportSource
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/Look.panel/Look_Tools.stack/Legend_Maker.pushbutton/script.py View on GitHub"""Draws the last color scheme as a PNG legend, shows it, and can save a viewpoint with those colors."""
import os
from namo import colorize, legend, naming, paint, session, ui
from pynavis import doc as nwdoc
from pynavis import output, script, toast
TITLE = 'Legend Maker'
DEFAULTS = {'view': False, 'folder': ''}
def default_folder(document, cfg):
"""The last folder used, else the document's folder, else Documents."""
if cfg.get('folder') and os.path.isdir(cfg['folder']):
return cfg['folder']
path = nwdoc.get_filename(document)
if path and os.path.isdir(os.path.dirname(path)):
return os.path.dirname(path)
from System import Environment
return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
def run():
scheme = paint.last_scheme()
if not scheme or not scheme.get('entries'):
toast.info('No color scheme yet', 'Run Color by Property, Color Presets or Status Painter first.')
return
document = nwdoc.get_doc()
cfg = script.get_config(DEFAULTS)
stem = os.path.splitext(os.path.basename(nwdoc.get_filename(document) or ''))[0]
path = os.path.join(default_folder(document, cfg), legend.default_name(scheme.get('title') or 'Legend', stem))
values = ui.form(TITLE, legend.form_fields(scheme, path, cfg), ok='Save legend')
if values is None:
return
title = naming.sanitize(values['title']).strip() or 'Legend'
target = values['path']
if not target.lower().endswith('.png'):
target += '.png'
cfg.update({'view': values['view'], 'folder': os.path.dirname(target)})
script.save_config(cfg)
scheme = dict(scheme, title=title)
try:
_path, width, _height, data = legend.save_png(scheme, target)
except (IOError, OSError) as error:
toast.error('Could not save the legend', 'Close the file if another program has it open. %s' % error)
return
output.print_html(legend.image_html(data, width, target))
if not (values['view'] and document.Models.Count):
toast.success('Saved the legend', target)
return
try:
comment = '\n'.join(colorize.legend_lines(scheme))
name, with_colors = legend.save_view(legend.view_name(title), comment, document)
except Exception as error:
session.log('error', 'legend viewpoint not saved: %s' % error)
toast.warning('Saved the legend, not the viewpoint', 'Navisworks refused the viewpoint: %s' % error)
return
if with_colors:
toast.success('Saved the legend and a viewpoint', 'Recall "%s" to bring these colors back. %s'
% (name, target))
else:
toast.success('Saved the legend and a viewpoint', '"%s" holds the camera only: no colors were '
'applied when it was saved. %s' % (name, target))
run()
Library modules this tool uses
From the shared namo library, which installs with every tool. Each name opens the module on GitHub.
namo.colorizeColouring by property: the engine behind Color by Property, Color Presets and Status Painter.namo.legendLegend Maker: a colour scheme drawn as a print-ready PNG legend.namo.namingName templates: '{test} - {n:000}', '{date:%Y%m%d} {project}', '{{literal braces}}'.namo.paintColouring model items: permanent colour/transparency overrides, ghosting, reset.namo.sessionState that outlives one run, plus the one logger every namo module shares.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/Look.panel/Look_Tools.stack/Legend_Maker.pushbutton/bundle.yaml View on GitHubtitle: Legend Maker
tooltip: Draws the last color scheme as a print-ready PNG legend with swatches and counts, and can save a viewpoint that brings those colors back.
context: doc