Skip to content

Commit

Permalink
Merge pull request #1664 from jmcouffin/feature/bundle_creator
Browse files Browse the repository at this point in the history
 extension for single button, bundles and panel creation 
extra: added python and yaml snippets
  • Loading branch information
jmcouffin authored Jan 19, 2023
2 parents 420a0ed + 255d48a commit 9363233
Show file tree
Hide file tree
Showing 27 changed files with 5,117 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extensions/*
!extensions/pyRevitTutor.extension/
!extensions/extensions.json
!extensions/README.md
!extensions/pyRevitBundlesCreatorExtension.extension/

# ignore visual studio files
**/.vs
Expand Down
9 changes: 5 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"python.linting.pylintEnabled": true,
"python.linting.pylintEnabled": false,
"python.linting.pylintArgs": ["--max-line-length=80"],
"python.linting.pylintUseMinimalCheckers": false,
"python.linting.pycodestyleEnabled": false,
"python.linting.flake8Enabled": false,
"python.linting.flake8Enabled": true,
"python.linting.pylamaEnabled": false,
"python.linting.mypyEnabled": false,
"python.jediEnabled": true,
"restructuredtext.confPath": "${workspaceFolder}/docs",
"python.formatting.provider": "black",
"python.formatting.provider": "autopep8",
"python.languageServer": "Jedi",
"python.formatting.blackArgs": [
"--line-length=80"
Expand All @@ -29,5 +29,6 @@
"**/__pycache__": true,
"**/Prerequisites": true,
},
"python.pythonPath": "C:\\Users\\ehsan\\.virtualenvs\\pyrevit-dev-2PO7Kqjk\\Scripts\\python.exe"
"python.pythonPath": "C:\\Users\\ehsan\\.virtualenvs\\pyrevit-dev-2PO7Kqjk\\Scripts\\python.exe",
"python.linting.enabled": true
}
98 changes: 98 additions & 0 deletions .vscode/snippets/python.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"pyRevit snippet 1": {
"scope": "python",
"prefix": "pyr1",
"body": [
"# -*- coding: utf-8 -*-",
"",
"from pyrevit import revit, DB, forms, script",
"",
"output = script.get_output()",
"output.close_others()",
"",
"doc = revit.doc",
"uidoc = revit.uidoc",
"",
"${1:collector_name} = DB.FilteredElementCollector(doc).OfCategory(DB.BuiltInCategory.${2:OST_Walls}).WhereElementIsNotElementType().ToElements()",
"",
"${3:class}_ids = []",
"for element in ${1:collector_name}:",
" print(element.Id)"
],
"description": "snippet for pyRevit"
},
"pyRevit snippet 2": {
"scope": "python",
"prefix": "pyr2",
"body": [
"# -*- coding: utf-8 -*-",
"",
"from pyrevit import revit, DB, forms, script",
"",
"output = script.get_output()",
"output.close_others()",
"",
"doc = revit.doc",
"uidoc = revit.uidoc",
"",
"${1:collector_name} = DB.FilteredElementCollector(doc).OfCategory(DB.BuiltInCategory.${2:OST_Walls}).WhereElementIsNotElementType().ToElements()",
"",
"${3:class}_ids = []",
"${3:class}_heights = []",
"${3:class}_type_names = []",
"",
"for element in ${1:collector_name}:",
" ${3:class}_ids.append(output.linkify(element.Id))",
" ${3:class}_height = element.get_Parameter(DB.BuiltInParameter.${4:WALL_USER_HEIGHT_PARAM}).AsValueString()",
" ${3:class}_heights.append(${3:class}_height)",
" ${3:class}_type_name = element.LookupParameter(\"Type\").AsValueString()",
" ${3:class}_type_names.append(${3:class}_type_name)",
"",
"output.print_md(\"# ${3:class}\")",
"output.print_table(zip(${3:class}_ids, ${3:class}_heights, ${3:class}_type_names), columns=[\"Id\", \"${5:Parameter Name}\", \"${3:class} Type Name\"])",
"$6"
],
"description": "more advanced snippet for pyRevit"
},
"pyRevit snippet 3": {
"scope": "python",
"prefix": "pyr3",
"body": [
"# -*- coding: utf-8 -*-",
"",
"from pyrevit import revit, DB, forms, script",
"",
"output = script.get_output()",
"output.close_others()",
"",
"doc = revit.doc",
"uidoc = revit.uidoc",
"",
"def ${0:def_name}():",
" # create a filter for walls with analytical model deactivated",
" param = DB.BuiltInParameter.STRUCTURAL_ANALYTICAL_MODEL",
" provider = DB.ParameterValueProvider(DB.ElementId(param))",
" evaluator = DB.FilterNumericEquals()",
" rule = DB.FilterIntegerRule(provider, evaluator, 0)",
" filter = DB.ElementParameterFilter(rule)",
" ${1:collector_name} = DB.FilteredElementCollector(doc).OfCategory(DB.BuiltInCategory.${2:OST_Walls}).WherePasses(filter).WhereElementIsNotElementType().ToElements()",
" return ${1:collector_name}",
"",
"${3:class}_ids = []",
"${3:class}_heights = []",
"${3:class}_type_names = []",
"",
"for element in ${0:def_name}():",
" ${3:class}_ids.append(output.linkify(element.Id))",
" ${3:class}_height = element.get_Parameter(DB.BuiltInParameter.${4:WALL_USER_HEIGHT_PARAM}).AsValueString()",
" ${3:class}_heights.append(${3:class}_height)",
" ${3:class}_type_name = element.LookupParameter(\"Type\").AsValueString()",
" ${3:class}_type_names.append(${3:class}_type_name)",
"",
"output.print_md(\"# ${3:class}\")",
"output.print_table(zip(${3:class}_ids, ${3:class}_heights, ${3:class}_type_names), columns=[\"Id\", \"${5:Parameter Name}\", \"${3:class} Type Name\"])",
"$6"
],
"description": "more advanced snippet for pyRevit defining a function and a filtered collector"
}
}
15 changes: 15 additions & 0 deletions .vscode/snippets/yaml.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"Bundle.yaml for pyRevit": {
"scope": "yaml",
"prefix": "yam",
"body": [
"title:",
" fr_fr: ${1: french title}",
" en_us: ${2: english title}",
"tooltip: ",
" fr_fr: ${3: french tooltip}",
" en_us: ${4: english tooltip}"
],
"description": "bundle.yaml for pyRevit"
}
}
14 changes: 14 additions & 0 deletions extensions/pyRevitBundlesCreatorExtension.extension/extension.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"builtin": "True",
"default_enabled": "False",
"type": "extension",
"rocket_mode_compatible": "True",
"name": "pyRevitBundlesCreatorExtension",
"description": "Button to create buttons and panels for pyRevit",
"author": "Jean-Marc Couffin",
"author_profile": "https://www.linkedin.com/in/jmcouffin/",
"url": "https://github.com/eirannejad/pyRevit.git",
"website": "http://eirannejad.github.io/pyRevit/",
"image": "",
"dependencies": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title:
fr_fr: Créer des boutons
en_us: Create Buttons
tooltip:
fr_fr: Créer des boutons
en_us: Create Buttons
context: zero-doc
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# -*- coding=utf-8 -*-
"""
Create a new button from a template of button bundles.
"""

import os
import shutil
from pyrevit.forms import ask_for_string, alert, CommandSwitchWindow
from pyrevit import script, forms
from pyrevit.loader import sessionmgr

# base folders structure
current_folder = os.path.dirname(__file__)
up_1_folder = os.path.dirname(current_folder)
button_types_folder = "button_types"
button_types_folder = os.path.join(up_1_folder, button_types_folder)
up_2_folder = os.path.dirname(up_1_folder)

# get panel name and create folder
panel_name = forms.ask_for_string(
default="My New Panel Name", title="New panel", prompt="Get your new panel a name")
panel_folder = os.path.join(up_2_folder, panel_name + ".panel")
if not os.path.exists(panel_folder):
os.mkdir(panel_folder)

# to extend add entry to dict: {"button type": ["bundle extension", "button template folder"]}
buttton_type_dict = {"pushbutton": ["pushbutton", "pushbutton"],
"pushbutton with config": ["pushbutton", "pushbutton_with_config"],
"pushbutton for Dynamo script": ["pushbutton", "pushbutton_for_dynamo_script"],
"content button": ["content", "content_button"],
"url button": ["urlbutton", "url_button"],
"invoke C# dll button": ["invokebutton", "invoke_dll_button"],
}


def button_template(button_type):
button_folder = "pushbutton"
button_template_folder_str = "pushbutton"
if button_type in buttton_type_dict:
button_folder = buttton_type_dict[button_type][0]
button_template_folder_str = buttton_type_dict[button_type][1]
button_template_folder = os.path.join(
button_types_folder, button_template_folder_str)
return button_folder, button_template_folder


def create_button(button_type):
button_folder, button_template_folder = button_template(button_type)
newname = ask_for_string(
title="New Folder", instructions="Specify name for new button")
if not newname:
alert("No name specified, will exit")
script.exit()
new_button_folder = os.path.join(
panel_folder, newname + "." + button_folder)

if os.path.exists(new_button_folder):
alert("Folder already exists")
else:
os.mkdir(new_button_folder)
for f in os.listdir(button_template_folder):
file = os.path.join(button_template_folder, f)
shutil.copy(file, new_button_folder)
# copy bin folder to root of newfolder in invokebutton
if button_type == "invoke C# dll button":
bin_template_folder = os.path.join(button_types_folder, "bin")
bin_folder = os.path.join(panel_folder, "bin")
if not os.path.exists(bin_folder):
os.mkdir(bin_folder)
for f in os.listdir(bin_template_folder):
file = os.path.join(bin_template_folder, f)
shutil.copy(file, bin_folder)

for copied_file in os.listdir(new_button_folder):
if copied_file.endswith(".yaml"):
# get english title string and replace with newname
path = os.path.join(new_button_folder, copied_file)
with open(path, "r") as f:
lines = f.readlines()
with open(path, "w") as f:
for line in lines:
if " en_us: english title" in line:
line = " en_us: {}\n".format(newname)
f.write(line)


while True:
button_type_selected = CommandSwitchWindow.show(
buttton_type_dict.keys(), message="Select button type")
if button_type_selected:
create_button(button_type_selected)
res = alert("Create another one?", title="Create another button?", yes=True,
no=True, ok=False, warn_icon=False, footer="pyRevit Bundle Creator")
if res is False:
sessionmgr.reload_pyrevit()
break
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title:
en_us: english title
fr_fr: french title
tooltip:
en_us: english tooltip
fr_fr: french tooltip
# highlight: new
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title:
en_us: english title
fr_fr: french title
tooltip:
en_us: english tooltip
fr_fr: french tooltip
# highlight: new
context: zero-doc
assembly: AliTpyRevitConcepts.dll
command_class:
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title:
en_us: english title
fr_fr: french title
tooltip:
en_us: english tooltip
fr_fr: french tooltip
# highlight: new
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-

from pyrevit import revit, forms, script
from pyrevit import DB as DB

output = script.get_output()
output.close_others()

doc = revit.doc
uidoc = revit.uidoc

wall_instances = (
DB.FilteredElementCollector(doc)
.OfCategory(DB.BuiltInCategory.OST_Walls)
.WhereElementIsNotElementType()
.ToElements()
)

output.print_md('# Hello World')
output.print_md('{0} walls found in the model.'.format(len(wall_instances)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
engine:
clean: true
title:
en_us: english title
fr_fr: french title
tooltip:
en_us: english tooltip
fr_fr: french tooltip
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9363233

Please sign in to comment.