Get Instance Parameter Value By Name


#1

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.


#2

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].


#3

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!