Skip to content
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

Update SumTotal to support Revit 2023 #1566

Merged
merged 1 commit into from
Sep 3, 2022
Merged
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import namedtuple

from pyrevit import revit, DB
from pyrevit import revit, DB, HOST_APP
from pyrevit.compat import safe_strtype
from pyrevit import forms
from pyrevit import script
Expand All @@ -13,7 +13,7 @@
logger = script.get_logger()
output = script.get_output()

ParamDef = namedtuple('ParamDef', ['name', 'type'])
ParamDef = namedtuple('ParamDef', ['name', 'type', 'readableTypeName'])


def is_calculable_param(param):
Expand All @@ -27,6 +27,17 @@ def is_calculable_param(param):

return False

def get_definition_type(definition):
if HOST_APP.is_newer_than(2022):
return definition.GetDataType()
else:
return definition.ParameterType

def get_definition_readableTypeName(definition):
if HOST_APP.is_newer_than(2022):
return DB.LabelUtils.GetLabelForSpec(definition.GetDataType())
else:
return definition.ParameterType

def calc_param_total(element_list, param_name):
sum_total = 0.0
Expand Down Expand Up @@ -79,8 +90,12 @@ def format_volume(total):
total/35.3147,
(total/35.3147)*1000000)


formatter_funcs = {DB.ParameterType.Length: format_length,
if HOST_APP.is_newer_than(2022):
formatter_funcs = {DB.SpecTypeId.Length: format_length,
DB.SpecTypeId.Area: format_area,
DB.SpecTypeId.Volume: format_volume}
else:
formatter_funcs = {DB.ParameterType.Length: format_length,
DB.ParameterType.Area: format_area,
DB.ParameterType.Volume: format_volume}

Expand Down Expand Up @@ -118,7 +133,8 @@ def process_options(element_list):
if is_calculable_param(param):
pdef = param.Definition
shared_params.add(ParamDef(pdef.Name,
pdef.ParameterType))
get_definition_type(pdef),
get_definition_readableTypeName(pdef)))

# find element type parameters
el_type = revit.doc.GetElement(el.GetTypeId())
Expand All @@ -127,7 +143,8 @@ def process_options(element_list):
if is_calculable_param(type_param):
pdef = type_param.Definition
shared_params.add(ParamDef(pdef.Name,
pdef.ParameterType))
get_definition_type(pdef),
get_definition_readableTypeName(pdef)))

param_sets.append(shared_params)

Expand All @@ -137,7 +154,7 @@ def process_options(element_list):
for param_set in param_sets[1:]:
all_shared_params = all_shared_params.intersection(param_set)

return {'{} <{}>'.format(x.name, x.type): x
return {'{} <{}>'.format(x.name, x.readableTypeName): x
for x in all_shared_params}


Expand Down