I’ve been trying to get the parameters of an element. However, I have noticed that the below code runs only in IronPython when I remove the - #!python3 tag. However, the code doesn’t run with the #!python3 tag. I am unable to use get_parameter to get any parameter of BuiltInParameter in CPython. Is there any fix for this because I need to access the parameters and I am using pandas to store the retrieved parameters in a dataframe but am unable to extract the parameters in CPython
#!python3
collector = FilteredElementCollector(doc).WhereElementIsNotElementType()
BIPs = [
BuiltInParameter.STAIRS_BASE_LEVEL_PARAM,
BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM,
]
for element in collector:
if element.Category and element.Category.HasMaterialQuantities:
if element.LevelId.Equals(ElementId.InvalidElementId):
for BIP in BIPs:
param = element.get_Parameter(BIP)
# exec("param = %s" % BIP)
# param = element.get_Parameter(BuiltInParameter.STAIRS_BASE_LEVEL_PARAM)
if param:
param_elem_id = param.AsElementId()
print(param_elem_id)
if param_elem_id.Compare(ElementId.InvalidElementId) == 1:
elem_level = param_elem_id
break
else:
elem_level = element.LevelId
else:
elem_level = elem_level.Name
@adarsh.bim ,
i have on top at any script:
# -*- coding: utf-8 -*-
Gives me the same error. No change.
@adarsh.bim ,
your code runs…
i did just a slidly change to the collector
# 🏓 get all elements
collector = FilteredElementCollector(doc).WhereElementIsNotElementType().ToElements()
Are you running the code with #!python3 tag on top?
Without the tag, the code runs in IronPython, but with the tag it doesn’t run in CPython. Even with the ToElements(), it throws an error.
The exact error is -
TypeError : No method matches given arguments for get_Parameter: (<class 'int'>)
adarsh.bim:
#!python3
no without this comment, when i add this comment it does not work i only use
# -*- coding: utf-8 -*-
Since I am using Pandas I have to use this - #!python3
Since get_parameter and BuiltInParameter doesn’t work in CPython apparently, I used python subprocess to separate the code with IronPython handling all the BuiltInParameters and the python subprocess handing pandas.
opened 10:44PM - 12 Feb 23 UTC
closed 08:34AM - 21 Jun 23 UTC
Python 3
**Describe the bug**
The Dynamo version of [Topologic](https://topologic.app/so… ftware/) relies on an older DLLs. [topologicpy](https://pypi.org/project/topologicpy/) relies on newer DLLs and has desirable added features for use with pyRevit CPython. I am trying to use methods from Topologic in Dynamo graphs and topologicpy in pyRevit in the same Revit session. If Topologic Dynamo graphs are used first subsequent topologicpy CPython scripts can't import necessary modules. If topologicpy CPython scripts are used first subsequent Topologic Dynamo graphs have broken nodes because Dynamo claims it cannot find the required Topologic package.
The problem concept faced seems to be described fairly well by: [How to use two versions of the same DLL in the same project](https://www.learningsomethingnew.com/how-to-use-two-versions-of-the-same-dll-in-the-same-project).
**To Reproduce**
1. Run Topologic Dynamo graph,
2. Run topologicpy CPython script,
3. topologicpy CPython script cannot import necessary module.
1. Run topologicpy CPython script,
2. Run Topologic Dynamo graph,
3. Dynamo graph has broken nodes because Dynamo claims it cannot find the required package.
**Expected behavior**
I was hoping the CPython environment would be isolated in something like a virtual environment. But it seems like DLLs are applied universally in a Revit session. As a result, the Dynamo Topologic package based on Python infrastructure that varies across distribution channels includes functions whose use is mutually excluded. This was not expected.
**Desktop (please complete the following information):**
- OS: Windows 10
- pyRevit Version: "4.8.12.22247+0031"
- pyRevit Environment:
```
==> Registered Clones (full git repos)
==> Registered Clones (deployed from archive/image)
master | Deploy: "basepublic" | Branch: "master" | Version: "4.8.12.22247+0031" | Path: "C:\Users\admin\AppData\Roaming\pyRevit-Master"
==> Attachments
master | Product: "2021.1.3" | Engine: IPY277 (277) | Path: "C:\Users\admin\AppData\Roaming\pyRevit-Master"
master | Product: "2020.2.3" | Engine: IPY277 (277) | Path: "C:\Users\admin\AppData\Roaming\pyRevit-Master"
==> Installed Extensions
ReTools | Type: Unknown | Repo: "" | Installed: "\\ripcord-nas0\Ripcord_Engineering\CAD\Autodesk\RVT\pyRevit\extensions\ReTools.extension"
==> Default Extension Search Path
C:\Users\admin\AppData\Roaming\pyRevit\Extensions
==> Extension Search Paths
\\ripcord-nas0\Ripcord_Engineering\CAD\Autodesk\RVT\pyRevit\extensions
==> Extension Sources - Default
https://github.com/eirannejad/pyRevit/raw/master/extensions/extensions.json
==> Extension Sources - Additional
==> Installed Revits
2021.1.3 | Version: 21.1.30.74 | Build: 20210426_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2021\"
2020.2.3 | Version: 20.2.30.42 | Build: 20200826_1250(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2020\"
==> Running Revit Instances
PID: 7648 | 2021.1.3 | Version: 21.1.30.74 | Build: 20210426_1515(x64) | Language: 0 | Path: "C:\Program Files\Autodesk\Revit 2021"
==> User Environment
Microsoft Windows 10 [Version 10.0.19044]
Executing User: WKSTN01\admin
Active User:
Admin Access: No
%APPDATA%: "C:\Users\admin\AppData\Roaming"
Latest Installed .Net Framework: 4.8
Installed .Net Target Packs: v3.5 v4.0 v4.5 v4.5.1 v4.5.2 v4.6 v4.6.1 v4.7 v4.7.2 v4.8 v4.X
Installed .Net-Core Target Packs: v3.1.426 v5.0.104 v5.0.416
pyRevit CLI v4.8.12.22247+0031
```
**Additional context**
The observed behavior is probably more of a mechanization observation than a bug. However, as an end user the behavior presents itself like a bug.
I looked around for a way that pyRevit might trigger a python script to run in an environment external to Revit. For my use case that should work well enough. However, I was not able to find guidance on how pyRevit might trigger a python script to run in an environment external to Revit.
Thank you for your consideration.
2 Likes
ay-e-x
(FBE)
May 7, 2024, 1:36pm
9
@adarsh.bim there is also a workaround for this in cpython,
without the ironpython/cpython split - but it is surely not the prettiest:
opened 01:41PM - 06 May 24 UTC
Bug
### ✈ Pre-Flight checks
- [X] I **don't have SentinelOne** antivirus installed … (see above for the solution)
- [X] I have **searched in the issues** (open and closed) but couldn't find a similar issue
- [X] I have **searched in the [pyRevit Forum](https://discourse.pyrevitlabs.io)** for similar issues
- [ ] I already **followed the [installation troubleshooting guide](https://pyrevitlabs.notion.site/Installation-issues-f6495adb56254e9e8021f8a68e3b2ab7) thoroughly**
- [ ] I am using the **latest pyRevit Version**
### 🐞 Describe the bug
When running these (apart from python3 shebang identical) snippets:
in ironpython:
```python
import clr
clr.AddReference("Autodesk")
from Autodesk.Revit.DB import BuiltInParameter as Bip
import sys
print(sys.version_info)
print(sys.implementation.name)
print("code: `type(Bip.LEVEL_IS_BUILDING_STORY)`")
print(type(Bip.LEVEL_IS_BUILDING_STORY))
```
and cpython
```python
#! python3
import clr
clr.AddReference("Autodesk")
from Autodesk.Revit.DB import BuiltInParameter as Bip
import sys
print(sys.version_info)
print(sys.implementation.name)
print("code: `type(Bip.LEVEL_IS_BUILDING_STORY)`")
print(type(Bip.LEVEL_IS_BUILDING_STORY))
```
with pyrevit engines ironpython 3.4.0 and cpython 3.8.5 I get different type results:
* on ironpython: `<class 'BuiltInParameter'>` (as expected)
* on cpython: `<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
```shell
if a parameter access is use with the above in cpython like so:
doc = __revit__.ActiveUIDocument.Document
print(doc.ActiveView.GenLevel.get_Parameter(Bip.LEVEL_IS_BUILDING_STORY))
the resulting error is as expected (it cannot find an overload with int as method argument):
CPython Traceback:
TypeError : No method matches given arguments for get_Parameter: (<class 'int'>)
File "C:\ProgramData\pyRevit_BH\sandbox.extension\pyRevit_BH.tab\Sandbox.panel\Sandbox.pulldown\bip_test_cPy3_Sandbox.pushbutton\bip_test_cPy3_Sandbox_script.py", line 16, in <module>
print(doc.ActiveView.GenLevel.get_Parameter(Bip.LEVEL_IS_BUILDING_STORY))
pyRevitLabs.PythonNet
at Python.Runtime.Runtime.CheckExceptionOccurred()
at Python.Runtime.PyScope.Exec(String code, IntPtr _globals, IntPtr _locals)
at Python.Runtime.PyScope.Exec(String code, PyDict locals)
at PyRevitLabs.PyRevit.Runtime.CPythonEngine.Execute(ScriptRuntime& runtime)
# ------
I get the impression that in cpython we get the integer back from the BuiltInParameter Enum instead of the expected BuiltInParameter class object.
```
### ♻️ To Reproduce
1. create new pyrevit button with the above snippets, for both ironpython and cpython.
2. run them and observe the different type output.
### ⏲️ Expected behavior
receiving `BuiltInParameter` type for both python interpreter versions.
### 🖥️ Hardware and Software Setup (please complete the following information)
```shell
* win 10 (19045)
* rvt 2024 (24.1.0.66)
* pyrevit 4.8.14
* ironpython 3.4.0
* cpython 3.8.5
```
### 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.
hopefully there will be a better way for this in future pyrevit cpython.
1 Like
jpitts
(JP)
May 7, 2024, 3:19pm
10
Does this work for CPython? From query.py in pyrevitlib
def get_builtinparameter(element, param_name, doc=None):
doc = doc or DOCS.doc
eparam = element.LookupParameter(param_name)
if eparam:
for biparam in DB.BuiltInParameter.GetValues(DB.BuiltInParameter):
if int(biparam) == eparam.Definition.Id.IntegerValue:
return biparam
I wasn’t aware of this before but will check it out thanks!
I might stick with the python subprocess as it is fairly straightforward and works perfectly since now I can divide my IronPython codes from my python3 codes without worrying about running into any future problems.
ay-e-x
(FBE)
May 8, 2024, 7:06am
12
@jpitts the downside with element.LookupParameter("parameter_name")
for BuiltInParameters is:
it is not UI-language agnostic (Revit assigns different names to the same BuiltInParameters depending on the Revit UI language).
in case if you have users of your pyRevit scripts with different Revit language settings, via LookupParameter
it will only work for the ones with matching language setting but not for others.
whereas the element.get_Parameter(Bip.BuiltInParameterName)
access works for any Revit language setting.
Kervin
(KERVIN CALERO)
April 22, 2025, 3:13am
13
Other ways to try to get BIPs in cp:
Wall = UnwrapElement(IN[0])
param = Wall.Parameter[BuiltInParameter.WALL_BASE_OFFSET].AsDouble()
#or
param = Wall.GetParameter(ParameterTypeId.WallBaseOffset).AsDouble
1 Like