Get parameter value with python

Hello everyone!

I need some help with getting values of elements. I wrote python code in dynamo to collect the value of highlighted parameter:
image

I used dynamo nodes for sorting data:

And here is the code of python script:

import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

import System
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = IN[0]
element = UnwrapElement(IN[1])

# First method
name = []
value = []
DB = element.GetParameters("Марка")
for i in DB:
	name.append(i.Definition.Name)
	value.append(i.AsValueString())

# Second method
# DB = element.get_Parameter(BuiltInParameter.ALL_MODEL_MARK)
# name = DB.Definition.Name
# value = DB.AsValueString()

OUT = name, value, DB

The result of my script is null:
image

What i’m doing wrong?

1 Like

What storage type is the parameter Марка? Is it equivalent to Mark? If so, the storage type is Text (string) and if you query it with AsValueString() it will return null. Try with AsString() instead

1 Like

Yes, it’s equivalent to Mark. Thank you Thomas! It works!
May be there is a simple way to find out what storage type of each parameter of the element?

I use the Revit Lookup addin to inspect parameters. You can get the latest version from lookupbuilds.com. It gives you lots of information:

4 Likes

Excuse me, let me ask you a question.
Only one element may be used for the above results.
Is there a way to get multiple factors?

You can put it within a loop

3 Likes

Thank you very much :>

hello, I’d like to do the same thing as above, but with more than one parameter. How would I do multiple parameters within an element? Thanks!

I copied the code exactly and tried this solution (“AsString()”) however is not working for me.

I am trying to read the value of a shared parameter…maybe this is the reason why this doesnt work. You tried it with values of family parameters, didnt you?

What sort of storage type is your shared parameter? AsString() is only appropriate if your parameter is text (string). If it is numeric then AsInteger() or AsDouble() or AsValueString() would be what is needed. You can see the descriptions of these methods here: Parameter Methods

The original query was for the built-in parameter Mark which is stored as a string. But whether it is a built-in, family, project or shared parameter doesn’t make any difference to retrieiving the value.

Here is a bit of code that hopefully can guide you on your way @dfgind

import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

import System
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

def getParam(element,param):
	value = []
	try:
		DB = element.GetParameters(param)
		for i in DB:
			if "Double" in str(i.StorageType): 
				# Metric Converstion
				value.append(i.AsDouble()*304.8)
			elif "Integer" in str(i.StorageType):
				value.append(i.AsInteger())
			elif "String" in str(i.StorageType):
				value.append(i.AsString())
			else:
				elemId =i.AsElementId()
				value.append(doc.GetElement(elemId))
	except:
		pass
	return value

input = tolist(IN[0])
params = IN[1]
result = []

# Get parameters for Multiple Elements
for i in input:
	pack = []
	for p in params:
		elem = UnwrapElement(i)
		pack.append(getParam(elem,p))
	result.append(pack)

OUT = result
4 Likes