Dev > Automate
Macro to Button
Makes a ribbon button in your MyTools extension that plays a macro, with its own icon and shortcut.
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
It needs these Navisworks event hooks, so installing it also copies the shared hooks folder:
after-command
Files
Paths are relative to the Playground.extension folder.
Dev.tab/Automate.panel/Macros.pulldown/Macro_to_Button.pushbutton/bundle.yamlDev.tab/Automate.panel/Macros.pulldown/Macro_to_Button.pushbutton/icon.dark.pngDev.tab/Automate.panel/Macros.pulldown/Macro_to_Button.pushbutton/icon.pngDev.tab/Automate.panel/Macros.pulldown/Macro_to_Button.pushbutton/icon.small.dark.pngDev.tab/Automate.panel/Macros.pulldown/Macro_to_Button.pushbutton/icon.small.pngDev.tab/Automate.panel/Macros.pulldown/Macro_to_Button.pushbutton/script.py
Install
- Only this tool. In Navisworks, click pyNavis > Playground, search for Macro to Button, 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. Macro to Button is on the Dev tab, Automate 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.
Dev.tab/Automate.panel/Macros.pulldown/Macro_to_Button.pushbutton/script.py View on GitHub# -*- coding: utf-8 -*-
"""Makes a button in your own MyTools extension that plays a macro."""
from pynavis import forms, script, toast
from namo import buttonmaker, hotkeys, macros, ribbon, ui
names = macros.names()
if not names:
toast.info('There are no macros yet', 'Record one with Record Macro first.')
else:
macro = forms.select_from_list(names, title='Macro to Button', prompt='Pick the macro the new button plays.')
if macro is not None:
root = buttonmaker.user_root()
last = script.get_config({'tab': buttonmaker.DEFAULT_TAB, 'panel': 'Macros', 'icon': 'play'})
cfg, _error = hotkeys.read_config(ribbon.user_config_path())
allow_bare = hotkeys.allow_bare_of(cfg or {})
taken = buttonmaker.taken_chords(ribbon.buttons())
fields = buttonmaker.form_fields(dict(last, title=macro), buttonmaker.existing_tabs(root), macro=True)
values = ui.form('Macro to Button', fields, ok='Make button',
intro='The button plays the macro %s. It goes in your own MyTools extension.' % macro,
validate=lambda v: buttonmaker.validate_spec(buttonmaker.spec_from(v, macro), root,
taken, allow_bare))
if values is not None:
spec = buttonmaker.spec_from(values, macro)
spec['namo_lib'] = buttonmaker.namo_lib_folder()
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, plays %s.' % (plan['tab'], plan['panel'], macro)
if spec.get('shortcut'):
detail += ' Shortcut %s.' % 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.macrosMacros: record pyNavis commands, play them back in order, manage them.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/Automate.panel/Macros.pulldown/Macro_to_Button.pushbutton/bundle.yaml View on GitHubtitle: Macro to Button
tooltip: Makes a ribbon button in your MyTools extension that plays a macro, with its own icon and shortcut.