Getting Enum values in CPython3 returns integers

So here is the result with ForgeTypeId workaround :

For copy/paste :

#Retrieves user input
excel=IN[0]

#Creates a dictionary with returned integer as key and ParameterType Name as value
pTypesN = System.Enum.GetNames(ParameterType)
pTypesT = System.Enum.GetValues(ParameterType)
dictParamType = {}

for i in range(0,len(pTypesN)) :
	dictParamType[str(pTypesT[i])] = pTypesN[i]

#Gets all ForgeTypes
ForgeTypes = SpecUtils.GetAllSpecs()

pTypesFromForge = []

#Creates a sorted list of corresponding ParamterType Name to each ForgeType where it exists, if not inserts null value
for ft in ForgeTypes :
    try :
        ptKey = str(SpecUtils.GetParameterType(ft))
        pTypesFromForge.append(dictParamType[ptKey])
    except :
        pTypesFromForge.append(None)

#From user input parameter type name, stores the corresponding ForgeTypeId in a new list to be used with ExternalDefinitionCreationOptions
userForgeType = []

for uInput in excel :
    ind = pTypesFromForge.index(uInput)
    #For demo purpose get the TypeId which is human readable
    userForgeType.append([ForgeTypes[ind],ForgeTypes[ind].TypeId])


OUT = userForgeType

Because user Inputs are ParameterType names, getting a null should never happen.
But the mapping between ParameterType names and ForgeTypeId is not unique :

  • Custom : leads to a bunch of ForgeTypeId
  • Length : leads to both Length and sheetLength
  • Angle : leads to Angle and siteAngle

Given a bit of luck, the ones my users would use are the first ones, so index() works for me.

Hopefully this can help others as well.

3 Likes