Get Instance Parameter Value By Name

Hi.
I am trying to get instance parameters in a python script node.
The problem is I can’t retrieve the value.


As you can see, the parameter exists and have a value.
But if I try to get it AsString(), I get a None type error.

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 41, in
AttributeError: ‘NoneType’ object has no attribute ‘AsString’

my python code is:

import sys
import clr
# import Revit API
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
# import Revit API UI
clr.AddReference('RevitAPIUI')
# import Revit Services
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# import ProtoGeometry
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# get the current Revit Document
doc = DocumentManager.Instance.CurrentDBDocument
# get the current Revit application
app = DocumentManager.Instance.CurrentUIApplication.Application
# get the current UI application
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
# Dynamo inputs

# empty list for output
# Used to Ensure that object is in a list...
def tolist(obj1):
if hasattr(obj1,"__iter__"): return obj1
else: return [obj1]

elements = tolist(IN[0])
sheets = IN[1]

outList = []
familyType = []
# loop over elements to get instance parameter
for v in UnwrapElement(elements):
for e in sheets:
p1 = v.LookupParameter("Mark").AsString()
p2 = v.LookupParameter("Foam Density").AsString()
p3 = v.LookupParameter("Stud Spacing").AsString()
if p1 == e:
outList.append([e, p2, p3])

# Assign your output to the OUT variable.
OUT = outList

If anyone could help, I would greatly appreciate.

Hi @lucaspfmoreira,

Use Parameter.StorageType node to know what is the storage type of your parameter (string, integer, double…)

Your script is not formatted correctly so there could be some errors.
You should add a picture with the preview under the inputs IN[0] and IN[1].

2 Likes

Hi, Alban thank you for your answer.
It Had something to do with the storage type but the LookupParameter method would not bring the parameter value for nom text parameters.
So I ended up using the GetParameter method:

import sys
import clr
# import Revit API
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
# import Revit API UI
clr.AddReference('RevitAPIUI')
# import Revit Services
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager 
# import ProtoGeometry 
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# get the current Revit Document 
doc = DocumentManager.Instance.CurrentDBDocument
# get the current Revit application
app = DocumentManager.Instance.CurrentUIApplication.Application
# get the current UI application
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
# Dynamo inputs 

# empty list for output
# Used to Ensure that object is in a list...
def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]
	

elements = tolist(IN[0])
sheets = IN[1]

outList = []
familyType = []
list1=[]
list2=[]
list3=[]
list4=[]
# loop over elements to get instance parameter 
for i in UnwrapElement(elements):
	for e in sheets:
		p1 = i.LookupParameter("Mark").AsString()
 		if p1 == e:
 			p2 = i.GetParameters("Foam Density")
 			if p2 is None:
 				p2=0
 			p3 = i.GetParameters("Stud Spacing")
 			if p3 is None:
 				p3=0
 			p4 = i.GetParameters("Type")
 			if p4 is None:
 				p4=0
 			list1.append(p1)
 			list2.append(p2)
 			list3.append(p3)
 			list4.append(p4)
 			
r1=[]
r2=[]
r3=[]
r4=[]
for e in list1:
	r1.append(e)
	
for e in list2:
	for i in e:
		r2.append(i.AsDouble())

for e in list3:
	for i in e:
		r3.append(i.AsDouble()*12)

for e in list4:
	for i in e:
		r4.append(i.AsElementId())		
i = 0	
while i <len(r2) :
	outList.append( [ r1[i], r2[i], r3[i], r4[i] ] )
	i+=1
# Assign your output to the OUT variable.
OUT = outList

For the last parameter, it is a type parameter, but I don’t know how to get it.
the type name would suffice but even though the type shows as a text in the parameter list the storage type is Element Id.

How do I get the string value of the ElementId type?
If I try AsElementId() I end up getting the actual Element Id

Thanks Again!

Hi Lucas,
I have the same problem. Were you able to resolve this issue?
I appreciate any advise.
Have a good weekend

If you mean the Family Type name that is what I did:

If you meant the Element Id as a string.
I did,

string = str(Intance.LookupParameter("Parameter").AsElementId())

Thanks Lucas for the reply.
Let me explain in more detail. I am trying to extract all the beams with certain connection type with Python.
When I get ElementId() it just delivers me the ID number.
This command"string = str(Intance.LookupParameter(“Parameter”).AsElementId())" just converts the number to string. I need the actual string from the ID.
Do you know any method?
Thanks in advance!

Sorry, by the string do you mean the FamilyType?

One of the parameters of structural framing’s is “Start Connection” or “End Connection”.
I’m trying to extract the value of this parameter which is a string like" Type A Connection".
I was able to extract the ID associated with the value of this parameter which is a string.

builtinparam=BuiltInParameter.STRUCT_CONNECTION_BEAM_START
output=bbs[0].GetParameters(“End Connection”)
OUT = output

and the output is: Autodesk…Revit.DB.Parameter

GetParameters("End Connection") does just that… it gets the parameter with the name “End Connection”.

If you want to get the value of that parameter then you need to do something similar to the original post where they got the Element Id with .AsElementId(). In this case you would use .AsValueString() to get the string value of the End Connection parameter.

Thank you very much Nick, .AsValueString() worked.