I am trying to convert some of my IronPython 2.7 scrips to cPython3 to be used with the newer versions of Dynamo. 2.7 gives us direct access to the Enums through “System.Enum.GetValues(BuiltInCategory)” whereas cPython3 returns the element id.
What I was doing.
def builtInCategories():
builtInCategories = {}
for bic in System.Enum.GetValues(BuiltInCategory):
builtInCategories[bic.ToString()] = bic
return builtInCategories
This worked very well for my purposes.
I have been trying for some time now to convert this and have failed. I have managed to get the name of the BuiltInCategory but I cannot figure out how to get the Enum itself.
for bic in System.Enum.GetValues(BuiltInCategory):
name = System.Enum.GetName(BuiltInCategory, bic)
How can I get the enum itself to store in the dictionary? I have tried doc.GetElement() but it returns null
import sys
import clr
import System
#import net library
from System import Array
from System.Collections.Generic import List, IList, Dictionary
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
net_dict = Dictionary[System.String, BuiltInCategory]()
for i, j in zip(System.Enum.GetNames(BuiltInCategory), System.Enum.GetValues(BuiltInCategory)):
net_dict.Add(i,j)
OUT = net_dict