-
-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1664 from jmcouffin/feature/bundle_creator
extension for single button, bundles and panel creation extra: added python and yaml snippets
- Loading branch information
Showing
27 changed files
with
5,117 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
extensions/pyRevitBundlesCreatorExtension.extension/extension.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
7 changes: 7 additions & 0 deletions
7
...n/pyRevit Bundles Creator.tab/Button creation.panel/Button Creator.pushbutton/bundle.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Binary file added
BIN
+2.18 KB
...it Bundles Creator.tab/Button creation.panel/Button Creator.pushbutton/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 96 additions & 0 deletions
96
...ion/pyRevit Bundles Creator.tab/Button creation.panel/Button Creator.pushbutton/script.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+6 KB
...yRevit Bundles Creator.tab/Button creation.panel/button_types/bin/AliTpyRevitConcepts.dll
Binary file not shown.
Binary file added
BIN
+2.02 MB
...les Creator.tab/Button creation.panel/button_types/content_button/AT-AT_16488_content.rfa
Binary file not shown.
Binary file added
BIN
+492 KB
...eator.tab/Button creation.panel/button_types/content_button/Star_Wars_R2D2_4123_other.rfa
Binary file not shown.
7 changes: 7 additions & 0 deletions
7
...pyRevit Bundles Creator.tab/Button creation.panel/button_types/content_button/bundle.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Binary file added
BIN
+4.04 KB
... Bundles Creator.tab/Button creation.panel/button_types/content_button/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions
10
...evit Bundles Creator.tab/Button creation.panel/button_types/invoke_dll_button/bundle.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
Binary file added
BIN
+3.27 KB
...ndles Creator.tab/Button creation.panel/button_types/invoke_dll_button/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions
7
...ion/pyRevit Bundles Creator.tab/Button creation.panel/button_types/pushbutton/bundle.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Binary file added
BIN
+2.72 KB
...evit Bundles Creator.tab/Button creation.panel/button_types/pushbutton/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions
20
...nsion/pyRevit Bundles Creator.tab/Button creation.panel/button_types/pushbutton/script.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |
8 changes: 8 additions & 0 deletions
8
...s Creator.tab/Button creation.panel/button_types/pushbutton_for_dynamo_script/bundle.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Binary file added
BIN
+1.91 KB
...or.tab/Button creation.panel/button_types/pushbutton_for_dynamo_script/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.