Hello,
I am trying to get parameter value for the width of ducts using Python script, I find some examples in the web:
duct = UnwrapElement(IN[0])
out1 = []
for d in duct:
dlevel = d.GetParameters("Width")
out1.append(dlevel.AsValueString())
#OUT = out1
However, the dlevel is a list it self and I need to add a code in order to work. Otherwise, it retruns errors.
for d1 in dlevel:
My final code is like the below
duct = UnwrapElement(IN[0])
out1 = []
for d in duct:
dlevel = d.GetParameters("Width")
for d1 in dlevel:
out1.append(d1.AsValueString())
#OUT = out1
Does my code correct or Am I miss something?
Thanks.
Something like that if you want to get width of duct
def tolist(obj1):
if hasattr(obj1,'__iter__') : return obj1
else : return [obj1]
#Preparing input from dynamo to revit
duct = UnwrapElement(tolist(IN[0]))
out1 = []
for d in duct:
value = d.get_Parameter(BuiltInParameter.RBS_CURVE_WIDTH_PARAM).AsValueString()
out1.append(value)
OUT = out1
or use GetPrameters :
def tolist(obj1):
if hasattr(obj1,'__iter__') : return obj1
else : return [obj1]
#Preparing input from dynamo to revit
ducts = UnwrapElement(tolist(IN[0]))
out1 = []
for d in ducts:
pras = d.GetParameters("Width")
for p in pras:
out1.append(p.AsValueString())
OUT = out1
5 Likes
One more question. I use AsDouble and it returns 1. Is there any method to get the value in double or integer other than sort it out after using AsValueString()?
Can, you can custom by function, like that
def GetParameterValue(parameter):
value= None
if parameter.StorageType == StorageType.Double:
value = parameter.AsDouble()
elif parameter.StorageType == StorageType.Integer:
if parameter.Definition.ParameterType == ParameterType.Integer:
value = parameter.AsInteger()
else:
value = parameter.AsValueString()
elif parameter.StorageType == StorageType.String:
value = parameter.AsString()
elif parameter.StorageType == StorageType.ElementId:
value = parameter.AsElementId()
return value
1 Like
Sorry for my missing presentation. My question is that the duct width is 305mm, however it return to 1 if using AsDouble().
Is that I have to write a small function to remove the unit from AsValuString() in order to return 305?
Thanks for your reply.
The number 1 I guess is the unit of feet : 1feet = 304.8 mm => AsvalueString can become 305mm
1 Like
I forget this. Thanks you so much.