Python: ParameterType

Hi all, need some help to achieve a new custom node. I wanna set a ParameterType in a method. I managed to get all available PT with a dir(ParameterType) command, but the output is a string, not the PT.

My goal is to allow user to select from a list of ParameterType and set the choice as input for the method. but as I get a string, I can’t make it work. How can I filter ParameterType in Python?

Thanks.

Julien,

It looks as though you can use System.Enum.Parse to parse a string into an instance of an Enum. IronPython doesn’t have typeof, so I used clr.GetClrType instead. HTH

…standard default imports to Python Script…

import System

#The input to this node will be stored in the IN variable.

dataEnteringNode = IN

#test1 = System.Enum.IsDefined(clr.GetClrType(ParameterType),‘Text’) <- also works, produces value True

test2 = System.Enum.Parse(clr.GetClrType(ParameterType),‘Text’)

#Assign your output to the OUT variable

OUT = test2

3 Likes

Great idea, Julien. That’s exactly the kind of thing I had in mind when requesting this:

Just perfect David. exactly what I was looking for. far far above my present coding skill in fact. would never have found this alone. thanks and I hope you will find useful the packages I’m about to publish. I will probably make a blog post as it has to be handeld carefuly, it deals with shared parameter creation.

Sounds great, Julien! Credit where it’s due: The info about parsing Enums came from the .Net docs: http://msdn.microsoft.com/en-us/library/system.enum(v=vs.100).aspx; a bit about Enums in IronPython came from the IronPython docs: http://ironpython.net/documentation/dotnet/dotnet.html#enumerations, and the great tip about clr.GetClrType() came from: http://www.voidspace.org.uk/ironpython/dark-corners.shtml#the-ironpython-equivalent-of-typeof. This last looks like a fascinating resource (and book), for details on IronPython/.Net integration.

David, thanks for the links, especially that last one.