Skip to content

Door flip state #2663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
title:
ru: Направление двери
fr_fr: Porte Miroir/Non Miroir
en_us: Door Mirrored/Unmirrored
de_de: Tür Gespiegelt/Ungespiegelt
tooltip:
en_us: >-
Writes the mirror state (aka Left/Right) of doors back to an instance parameter 'Door Wing Opening Direction' in doors. This needs to be an instance parameter of type text with the option different values for group instances. Prints a summary of accomplished job including changes to previous state.

All families to treat need two shared parameters 'DoorFamilyOpeningDirection_standard' and 'DoorFamilyOpeningDirection_mirrored' as instances with values corresponding, as in family defined standard to write back to parameter 'Door Wing Opening Direction'.
For families who have a symmetry checkbox "Door Mirrored" standard value may be changed by conditional statement in family: (f.ex -> if(Door Mirrored, "1 Wing Right", "1 Wing Left"))

Prerequisites:
In 'FAMILY' as instance, standard value as "blocked" formula
[Parameter] - 'DoorFamilyOpeningDirection_standard'
[Parameter] - 'DoorFamilyOpeningDirection_mirrored'

In 'PROJECT' as instance:
[Parameter] - 'Door Wing Opening Direction'
de_de: >-
Schreibt den Zustand ungegespiegel/gespiegelt (Links/Rechts) von Türen zurück in einen Instanzparameter 'Door Wing Opening Direction' in doors. Es muss ein Instanzparameter vom Typ Text sein, mit der Option "Unterschiedliche Werte für das Exemplar einer Gruppe". Ein Bericht über den ausgeführten Auftrag einschließlich der Änderungen zum vorherigen Zustand wird angezeigt.

Alle zu behandelnden Familien benötigen zwei gemeinsame genutzte Parameter 'DoorFamilyOpeningDirection_standard' und 'DoorFamilyOpeningDirection_mirrored' als Instanzen mit Werten, die dem in der Familie definierten Standard entsprechen, um in den Parameter 'Door Wing Opening Direction' zurückzuschreiben.
Für Familien, die eine Option (bool) „Tür gespiegelt“ haben, kann der Standardwert auch durch eine Formel in der Familie geändert werden: (z.B. -> if(Tür gespiegelt, „1 Flügel DIN/Rechts“, „1 Flügel DIN/Links“))

Voraussetzungen:
In 'FAMILY' als Instanzparameter, Standardwert als „blockierte“ Formel
[Parameter] - 'DoorFamilyOpeningDirection_standard'
[Parameter] - 'DoorFamilyOpeningDirection_mirrored'

Im 'PROJEKT' als Instanzparameter mit der Option verschiedene "Unterschiedliche Werte für das Exemplar einer Gruppe":
[Parameter] - 'Door Wing Opening Direction'
fr_fr: >-
Réécrit l'état non-miroir/miroir (gauche/droite) des portes dans un paramètre d'instance 'Door Wing Opening Direction' dans les portes. Il doit s'agir d'un paramètre d'instance de type texte, avec l'option 'valeurs peuvent varier en fonction de l'occurrence de groupe'. Un rapport sur le travail effectué, y compris les modifications par rapport à l'état précédent, est affiché.

Toutes les familles à traiter nécessitent deux paramètres communs utilisés 'DoorFamilyOpeningDirection_standard' et 'DoorFamilyOpeningDirection_mirrored' en tant qu'instances avec des valeurs correspondant au standard défini dans la famille, afin de pouvoir réécrire dans le paramètre 'Door Wing Opening Direction'.
Pour les familles qui ont une option (bool) « Miroiter la porte », la valeur par défaut peut également être modifiée par une formule dans la famille : (par ex. -> if(Miroiter la porte, " 1 vantail droite ", " 1 vantail gauche "))

Conditions préalables :
Dans la ' FAMILLE ' comme paramètre d'instance, valeur par défaut comme formule 'bloquée'.
[paramètre] - 'DoorFamilyOpeningDirection_standard'
[paramètre] - 'DoorFamilyOpeningDirection_mirrored'

Dans le 'PROJET' comme paramètre d'instance avec l'option différentes 'valeurs peuvent varier en fonction de l'occurrence de groupe':
[paramètre] - 'Door Wing Opening Direction'
author: Jakob Steiner (special thanks to Erik Frits)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,113 @@
# -*- coding: utf-8 -*-

import time, sys
from pyrevit import script, DB, revit, DOCS, forms
from pyrevit.framework import List

doc = DOCS.doc
output = script.get_output()

DOORDIR_STANDARD_PARAM = "DoorFamilyOpeningDirection_standard"
DOORDIR_MIRRORED_PARAM = "DoorFamilyOpeningDirection_mirrored"
DOORDIR_WRITEBACK_PARAM = "Door Wing Opening Direction"
DOORDIR_ERROR_VALUE = "-" # Value if the family doesn't have shared param. above

# MAIN
timer_start = time.time()

# GET ALL DOORS
doors_collector = get_doors(doc=doc)

if not doors_collector:
forms.alert("No doors found in the model.", title="Warning")
script.exit()


if not model_has_parameter(DOORDIR_WRITEBACK_PARAM, doc=doc):
print(
"The parameter '{}' does not exist in the current document.\n"
"Please create the parameter as an instance parameter, option different values for groupes,\n"
"for the category doors in the project.".format(DOORDIR_WRITEBACK_PARAM)
)
script.exit()

count_parameter = 0
count_not_parameter = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this could be left out since it is len(doors) - count_parameter

doors_without_parameter = set()
data_doors_changed = []

with revit.Transaction(doc, "DoorMirrorState"):
for door in doors_collector:
try:
param_name = DOORDIR_MIRRORED_PARAM if door.Mirrored else DOORDIR_STANDARD_PARAM
value = get_param_value(get_param(door, param_name))
count_parameter += 1

except AttributeError:
value = DOORDIR_ERROR_VALUE
count_not_parameter += 1

door_family = door.get_Parameter(
DB.BuiltInParameter.ELEM_FAMILY_PARAM
).AsValueString()
door_type = door.get_Parameter(
DB.BuiltInParameter.ELEM_TYPE_PARAM
).AsValueString()
door_name = "{family}-{type}".format(family=door_family, type=door_type)
doors_without_parameter.add(door_name)

try:
door_out_param = door.LookupParameter(DOORDIR_WRITEBACK_PARAM)

door_out_param_old = door_out_param.AsString()
door_out_param_new = value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use value in the lines below, or rename value to door_out_param_new in the lines above, and get rid of this one

if door_out_param_old != door_out_param_new:
door_out_param_changed = "{} -> {}".format(
door_out_param_old, door_out_param_new
)
door_name = door.Name
door_changed_link = output.linkify(door.Id)
data_doors_changed.append(
[door_name, door_out_param_changed, door_changed_link]
)
door_out_param.Set(str(value))
except AttributeError:
forms.alert(
"Please make sure instance parameter exists: {}".format(
DOORDIR_WRITEBACK_PARAM
)
)
script.exit()

output.print_md(
"### Number of doors found in the project: {} \n"
"- With writeback parameters defined in door family: {}\n"
"- Without writeback parameters defined in door family: {}\n"
"- Parameters missing: '{}', '{}'\n"
"- You will find in the folder of the script a shared parameter file containing these parameters.\n"
"- The default writeback value for doors without defined values will be: '{}'\n"
"---\n".format(
len(doors_collector),
count_parameter,
count_not_parameter,
DOORDIR_STANDARD_PARAM,
DOORDIR_MIRRORED_PARAM,
DOORDIR_ERROR_VALUE,
)
)

output.print_md("### Door families without writeback parameter defined in family:")
output.print_md("- " + "\n - ".join(doors_without_parameter))
output.print_md("---\n### Changes to previous run of the script:")

if data_doors_changed:
output.print_table(
table_data=data_doors_changed,
title="Doors with changed parameters:",
columns=["Door", "Changed Value (old->new)", "ElementId"],
)
else:
output.print_md("*No doors with changed parameters were found.*")

elapsed_time = time.time() - timer_start
output.print_md("---\n#### Script has finished in {:.2f}s".format(elapsed_time))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.