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