Skip to content

Commit

Permalink
Now non-project-params are supported as well #1588
Browse files Browse the repository at this point in the history
  • Loading branch information
eirannejad committed Sep 6, 2022
1 parent 51e33ac commit fbd5a6a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Key Name,Comments,JAck
1,comment for item 1,500
2,comment for item 2,510
3,comment for item 3,510
4,comment for item 4,510
5,comment for item 5,510
6,comment for item 6,510
7,comment for item 7,510
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,44 @@ def update_key_schedule(keyschedule, category, fields, records, doc=None):
param.Set(sched_items[param_value])


def ensure_schedulable_parameters(category, parameter_defs, doc=None):
"""Create a temporary key schedule and check of all
parameter definitions are schedulable using ScheduleDefinition api
Args:
parameter_defs (list[tuple]): list of (name, type) tuples
"""
doc = doc or revit.doc
params_ensured = True
with revit.DryTransaction(doc):
temp_key_sched = DB.ViewSchedule.CreateKeySchedule(doc, category.Id)
fsched_field_names = [
x.GetName(doc)
for x in temp_key_sched.Definition.GetSchedulableFields()
]

for param_def in parameter_defs:
if param_def[0] not in fsched_field_names:
logger.critical(
"Missing schedulable parameter.\n"
'Name: "%s"\n'
"Type: %s\n"
"Category %s",
param_def[0],
param_def[1],
category.Name,
)
params_ensured = False

if not params_ensured:
logger.critical(
"Revit API does not allow creation of "
"Project Parameters. Please create the missing parameters "
"manually before importing the data from CSV file."
)
return params_ensured


def ensure_parameters(category, parameter_defs, doc=None):
"""Ensure parameters exist for given categoryself.
Expand Down Expand Up @@ -406,7 +444,7 @@ def read_csv_typed_data(csv_file):
# creates project params if not
# skip the first on since it is "Key Name" and only applies
# to elements inside a key schedule
if ensure_parameters(key_sched_cat, param_defs[1:]):
if ensure_schedulable_parameters(key_sched_cat, param_defs[1:]):
# create the schedule and fill with data now
create_key_schedule(
category=key_sched_cat,
Expand Down

0 comments on commit fbd5a6a

Please sign in to comment.