Hi everyone,
Thank you for your interest in this topic.
I feel like I should give you guys a bit more context. I am trying to “upgrade” a working Dynamo graph written mostly in IronPython 2 to CPython3.
This graph takes an ExcelFile from my users and :
- creates new shared parameter
- loads the parameter into the project
- OR updates the categories associated to it if the parameter already exists (for it is the only writable property of the
ElementBinding
)
To do so, at some point in my code, I need to create an ExternalDefinitionCreationOptions
which takes two arguments, the parameter name which is a String
and the parameter type which is an object of type Autodesk.Revit.DB.ParameterType
My process is to read the string from the Excel file, to collect all ParameterType
with System.Enum.GetValues(ParameterType)
, go through all of them comparing the excel input with the ParameterType name (through str(ParameterType)
) so I can store the ParameterType of class Autodesk.Revit.DB.ParameterType
in a new list
I would like to get the same result in CPython3 that I get in IronPython2
The issue seems to be the one @c.poupin pointed out but the proposed workaround in the other topic doesn’t work for me.
With :
dictParameterType = dict(zip(System.Enum.GetValues(ParameterType), System.Enum.GetNames(ParameterType)))
I get this error :
Unable to cast an object of type 'System.Int64' into a type 'System.String'
And building the dictionary the other way around :
dictParameterType = dict(zip(System.Enum.GetNames(ParameterType), System.Enum.GetValues(ParameterType)))
Returns once again a System.Int64
object when getting values (eg: dictParameterType["Text"]
returns 1 )
In the pythonnet GitHub, someone gives this workaround :
from Tests import TestClass, TestEnum
a = TestClass()
a.EnumMethod[TestEnum](TestEnum.FirstValue)
But I am unable to figure out how I can adapt it to my case. Especially because Autodesk.Revit.DB.ParameterType
is the class I am looking for and the Enum at the same time
Trying other proposed solutions did not work so far.
I hope someone can help me figure this one out and thanks again for your help !