Dev > Build

Button Maker

Makes a new ribbon button in your MyTools extension from a template or your own script, with an icon and an optional shortcut.

Tab and panelDev > Build
KindButton

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.

  • Dev.tab/Build.panel/Button_Maker.pushbutton/bundle.yaml
  • Dev.tab/Build.panel/Button_Maker.pushbutton/icon.dark.png
  • Dev.tab/Build.panel/Button_Maker.pushbutton/icon.png
  • Dev.tab/Build.panel/Button_Maker.pushbutton/icon.small.dark.png
  • Dev.tab/Build.panel/Button_Maker.pushbutton/icon.small.png
  • Dev.tab/Build.panel/Button_Maker.pushbutton/script.py

Install

  1. Only this tool. In Navisworks, click pyNavis > Playground, search for Button Maker, 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. Button Maker is on the Dev tab, Build 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.

Dev.tab/Build.panel/Button_Maker.pushbutton/script.py View on GitHub
# -*- coding: utf-8 -*-
"""Makes a new pyNavis button in your own MyTools extension."""
import io

from pynavis import script, toast

from namo import buttonmaker, hotkeys, ribbon, ui

root = buttonmaker.user_root()
last = script.get_config({'template': 'selection', 'tab': buttonmaker.DEFAULT_TAB,
                          'panel': buttonmaker.DEFAULT_PANEL, 'icon': 'letters'})
cfg, _error = hotkeys.read_config(ribbon.user_config_path())
allow_bare = hotkeys.allow_bare_of(cfg or {})
taken = buttonmaker.taken_chords(ribbon.buttons())

if globals().get('__runner__'):
    toast.info('Button Maker needs the Navisworks window', 'It cannot open under pynavis run.')
else:
    values = ui.form('Button Maker', buttonmaker.form_fields(last, buttonmaker.existing_tabs(root)),
                     ok='Make button', width=520,
                     intro='The new button goes in %s, which pyNavis loads by itself.'
                           % buttonmaker.extension_folder(root),
                     validate=lambda v: buttonmaker.validate_spec(buttonmaker.spec_from(v), root, taken, allow_bare))
    if values is not None:
        spec = buttonmaker.spec_from(values)
        problem = None
        if spec['template'] == 'file':
            try:
                with io.open(spec['script_file'], encoding='utf-8-sig') as handle:
                    spec['script_text'] = handle.read()
            except (IOError, OSError, UnicodeDecodeError) as error:
                problem = str(error)
        if problem:
            toast.error('Could not read the script', problem)
        else:
            try:
                plan = buttonmaker.make(root, spec)
            except (IOError, OSError, ValueError) as error:
                toast.error('Could not make the button', str(error))
            else:
                script.save_config(buttonmaker.remembered(values))
                ribbon.reload()
                detail = '%s > %s. Edit it with Script Editor.' % (plan['tab'], plan['panel'])
                if spec.get('shortcut'):
                    detail = '%s > %s, shortcut %s. Edit it with Script Editor.' % (plan['tab'], plan['panel'],
                                                                                    spec['shortcut'])
                toast.success('Added %s' % ribbon.flatten_title(spec['title']), detail)

Library modules this tool uses

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

  • namo.buttonmakerButton Maker: writes new pyNavis bundles into the user's own extension.
  • namo.hotkeysHotkey Manager: one list of every command, with chords you can assign or clear.
  • namo.ribbonThe ribbon as data: every pyNavis button and every native Navisworks command, and safe ways to run them from code. Shared by the Command Palette, macros, the Hotkey Manager, usage analytics and the Environment Doctor.
  • 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.

Dev.tab/Build.panel/Button_Maker.pushbutton/bundle.yaml View on GitHub
title: Button\nMaker
tooltip: Makes a new ribbon button in your MyTools extension from a template or your own script, with an icon and an optional shortcut.