Determine variable type of parameter prior to pushing value in Python

How do I tell what type of [project/shared/type] parameter I am attempting to write to?

i.e. FooBar is a Revit Type 'Number" so how do I get PTHYON to tell me that so I can cast all those arrays as ‘number’ (long?)

Is this what you’re asking?

1 Like

If you’re looking for the object type of a specific parameter you can always read that parameter first then check the object type of the returned value.

Do you mean the StorageType of the parameter? This will tell you whether it’s one of:

  • ElementId
  • Double
  • Integer
  • String

@Nick_Boyts Yes- that works- but in PYTHON… Admittedly I am new to visual programming & PPYTHON; converting that to PYTHON SCRIPT may be obvious to more seasoned folks- but not quite for me yet.

@T_Pover Yes- so as I read out of a TXT or Excel file - I would like to cast the variable type to match the parameter type I am pushing to in PYTHON SCRIPT.

PYTHON Type() function: I am guessing any variable will take on the TYPE of the data pushed into it… So if
X=[1.1,2.2,3.3]
Type(X) would return LIST
type then if I set
X=32.4
Type(x) should a TYPE SINGLE(Or Double or float etc.)?

It’s kind of hard to tell what exactly you want to do, force a string to a number? or find out the parameters storagetype? Maybe you could show some of your graph and where you are stuck?

Python doesn’t have the usual strong typed syntax that other languages have (C# for example). Let us see the exact code snippet otherwise we can’t really help beyond the usual guessing that is going around right now.

Also, you can do something like this:

# get parameter object
parameter = element.get_Parameter(BuiltInParameter.SomeParam)

# get it's storage type
storageType = parameter.StorageType

# check storage type and do appropriate cast/parsing
if(storageType.ToString() == "String"):
    # do something
elif(storageType.ToString() == "ElementId"):
    # convert to element id
    id = ElementId(someInputValue)
else:
    # finally something else
...etc

This is awful pseudo code so don’t just copy paste it…

6 Likes