Dev > Automate
Record Macro
Records the pyNavis commands you run next, so Play Macro can repeat them in order.
Status
Launched Ran inside Navisworks at least once with no error logged; nobody checked the result yet.
Ran headless under pynavis run against a sample model; no selection: ran to the end: 'Recording a macro'; result not checked by a person.
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/Macro_Record.toggle/bundle.yamlDev.tab/Automate.panel/Macro_Record.toggle/icon.dark.pngDev.tab/Automate.panel/Macro_Record.toggle/icon.off.dark.pngDev.tab/Automate.panel/Macro_Record.toggle/icon.off.pngDev.tab/Automate.panel/Macro_Record.toggle/icon.on.dark.pngDev.tab/Automate.panel/Macro_Record.toggle/icon.on.pngDev.tab/Automate.panel/Macro_Record.toggle/icon.pngDev.tab/Automate.panel/Macro_Record.toggle/icon.small.dark.pngDev.tab/Automate.panel/Macro_Record.toggle/icon.small.pngDev.tab/Automate.panel/Macro_Record.toggle/script.py
Install
- Only this tool. In Navisworks, click pyNavis > Playground, search for Record Macro, 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. Record Macro 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/Macro_Record.toggle/script.py View on GitHub# -*- coding: utf-8 -*-
"""Starts recording the pyNavis commands you run, or stops and saves them as a macro."""
from pynavis import forms, script, toast
from namo import macros, naming
if not macros.is_recording():
macros.start_recording()
script.set_toggle_state(True)
toast.info('Recording a macro',
'Run pyNavis commands, then click Stop Recording. Navisworks commands record '
'when you run them from the Command Palette.')
else:
steps = macros.stop_recording()
script.set_toggle_state(False)
if not steps:
toast.info('Nothing was recorded', 'Click Record Macro, run some commands, then stop.')
else:
name = forms.ask_string('Name for this macro (%d step%s):' % (len(steps), '' if len(steps) == 1 else 's'),
default=naming.unique('Macro', macros.names()), title='Save macro')
if name is not None:
name = name.strip()
replace = True
if not name:
toast.warning('The macro was not saved', 'It needs a name. Save it from Manage Macros.')
replace = False
elif macros.load(name) is not None:
replace = forms.confirm('A macro called %s exists. Replace it?' % name, title='Save macro')
if name and replace:
try:
stored = macros.save(name, {'steps': steps})
except (IOError, OSError) as error:
toast.error('Could not save the macro', str(error))
else:
macros.forget_unsaved()
toast.success('Saved macro %s' % stored,
'%d step%s. Play it from the Macros menu.' % (len(steps), '' if len(steps) == 1 else 's'))
Library modules this tool uses
From the shared namo library, which installs with every tool. Each name opens the module on GitHub.
namo.macrosMacros: record pyNavis commands, play them back in order, manage them.namo.namingName templates: '{test} - {n:000}', '{date:%Y%m%d} {project}', '{{literal braces}}'.
bundle.yaml
The bundle contract: the keys pyNavis reads for this tool.
Dev.tab/Automate.panel/Macro_Record.toggle/bundle.yaml View on GitHubtitle: Record\nMacro
title_on: Stop\nRecording
tooltip: Records the pyNavis commands you run next, so Play Macro can repeat them in order.
tooltip_on: Stops recording and asks for a name for the macro.