Always searching to make things easier and quicker, I created a pyrevit button to create a new button whenever I want to start a script. It basically just creates the folders, copies in a script.py, bundle.yaml, and icon.png file from a template folder, opens the folder, and reloads pyrevit. It’s a great way to fill your toolbar with work in progress scripts that you never finish!
# -*- coding=utf-8 -*-
#pylint: disable=import-error,invalid-name,broad-except
import os
import shutil
import webbrowser
from pyrevit.forms import ask_for_string, alert
from pyrevit import script
from pyrevit.loader import sessionmgr
from pyrevit.loader import sessioninfo
def runscript():
lib = os.path.dirname(os.path.dirname(__file__))
template_folder = r"YOUR TEMPLATE FOLDER LOCATION HERE"
newname = ask_for_string(title="New Folder", instructions="Specify name for new command")
if not newname: return
newfolder = os.path.join(lib, newname + ".pushbutton")
if os.path.exists(newfolder):
alert("Folder already exists")
else:
os.mkdir(newfolder)
for f in os.listdir(template_folder):
file = os.path.join(template_folder, f)
shutil.copy(file, newfolder)
webbrowser.open(newfolder)
logger = script.get_logger()
results = script.get_results()
# re-load pyrevit session.
logger.info('Reloading....')
sessionmgr.reload_pyrevit()
results.newsession = sessioninfo.get_session_uuid()
Yes please. Maybe we can create an extension template that has a button to make buttons? @Jean-Marc I use this vscode extension to include project-level snippets. You can add all yours to .vscode/snippets.code-snippets in the pyRevit projects and commit so others can use them as well
Here’s an adapted version of @Jean-Marc 's vscode snippet! I kept forgetting the line break options for my wordy tooltips, so I embedded them in the snippet.
"Bundle.yaml for pyRevit": {
"scope": "yaml",
"prefix": "yy",
"body": [
"title:",
" en_us: ${1:english title}",
"tooltip: ",
"# en_us: \"slash n adds a line break \\nin the note\"",
"# en_us: \"For long notes, I like to add a line breaks ",
"# in the yaml but NOT in the tooltip. Spaces at the ",
"# start of a new line are ignored.\"",
" en_us: ${2:english tooltip}",
"Author: ${3:script author}",
"min_revit_version: ${4:version}",
"is_beta: ${5:false}",
],
"description": "bundle.yaml for pyRevit"
}
And here’s the resulting output:
title:
en_us: english title
tooltip:
# en_us: "slash n adds a line break \nin the note"
# en_us: "For long notes, you need to be able add a line break
# in the yaml but NOT in the note. The at the start of
# the new line are ignored."
en_us: english tooltip
Author: script author
min_revit_version: version
is_beta: false