Open ay-ex opened 4 months ago
I just tested it on pyRevit 4.8.16 , cpython 3.8.5 - same issue there.
a possible workaround is to go via forge_type_id - it is not pretty though: 🤔
from Autodesk.Revit.DB import BuiltInParameter as Bip
from Autodesk.Revit.DB import ForgeTypeId, ParameterUtils
doc = revit.ActiveUIDocument.Document param = doc.ActiveView.GenLevel.GetParameter(ForgeTypeId(ParameterUtils.GetParameterTypeId(getattr(Bip, "LEVEL_IS_BUILDING_STORY")).TypeId))
but already the next step: `param.StorageType` is your yet another enum that only returns int.
* via creating dict as lookup table for BuiltInCategory:
```python
print(35*"-")
print("bic: forge_type_id_by_cat_name")
from Autodesk.Revit.DB import BuiltInCategory as Bic
from Autodesk.Revit.DB import Category
forge_type_id_by_cat_name = {}
for bic_cat in dir(Bic):
if bic_cat.startswith("OST_"):
bic_name = bic_cat.split("OST_")[-1]
bic = getattr(Bic, bic_cat)
if Category.IsBuiltInCategoryValid(bic):
ftid = Category.GetBuiltInCategoryTypeId(bic)
forge_type_id_by_cat_name[bic_name] = ftid.TypeId
# print(ftid.TypeId)
else:
pass
# print("skipped: ", bic_name)
print(f"found {} ftids".format(len(forge_type_id_by_cat_name)))
# for k, v in sorted(forge_type_id_by_cat_name.items()):
# print(k, v)
print(35*"-")
print("bip: forge_type_id_by_param_name")
from Autodesk.Revit.DB import BuiltInParameter as Bip
from Autodesk.Revit.DB import ForgeTypeId, ParameterUtils
forge_type_id_by_param_name = {}
skip_names = { "INVALID", "Overloads", }
for bip_name in dir(Bip):
if bip_name in skip_names:
continue
if bip_name.endswith("__"):
continue
bip = getattr(Bip, bip_name)
if "method" in str(bip) or "function" in str(bip):
continue
ftid = ParameterUtils.GetParameterTypeId(bip).TypeId
# print(bip_name, ftid)
forge_type_id_by_param_name[bip_name] = ftid
print("found {} ftids:".format(len(forge_type_id_by_param_name)))
so ideally there could be a fix with which we could access enums in pyRevit cpython the same way as in ironpython. 🤔
Hi @ay-ex, sorry for the delay in the response.
This is a known bug of the version of pythonnet currently used by pyrevit. It was solved in version 3.0. We're trying to update it alongside the upgrade to the .net8 sdk to support revit 2025. As this was not our project originally and we're not super c# experts, we're trying to do the best we can to reach this goal. The upcoming pyrevit version 5 should fix this issue (no ETA yet, unfortunately).
hi @sanzoghenzo , no worries and thank you for the notification. 🙂 looking forward to pyRevit 5.
Hi @ay-ex,
The WIP installer has the updated version of pythonnet, can you try it to see if the problem persists?
@sanzoghenzo thank you so much for the notification! 🙂 I am currently fairly swamped, but as soon a I get a chance, I will try it and give feedback.
✈ Pre-Flight checks
🐞 Describe the bug
When running these (apart from python3 shebang identical) snippets: in ironpython:
and cpython
with pyrevit engines ironpython 3.4.0 and cpython 3.8.5 I get different type results:
<class 'BuiltInParameter'>
(as expected)<class 'int'>
(not as expected)this prevents me from using
level.get_Parameter(Bip.LEVEL_IS_BUILDING_STORY)
to access ui-language-agnostic parameter values for built-in-parameters.⌨ Error/Debug Message
♻️ To Reproduce
⏲️ Expected behavior
receiving
BuiltInParameter
type for both python interpreter versions.🖥️ Hardware and Software Setup (please complete the following information)
Additional context
there is a discussion on the forum describing the same problem: https://discourse.pyrevitlabs.io/t/getting-parameters-of-element-in-cpython/3011 so far there is no solution mentioned there.