Someone @Kulkul @craig @Einar_Raknes could write the final code for reading the parameter value. Because i’m trying this and of course returns me the parameter name, not the value:
import clr
# Import RevitAPI
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import FamilyManager
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
pl = doc.FamilyManager.Parameters
Name_Parameter = IN[0]
for p in pl:
a = p.Definition.Name
if a == Name_Parameter:
OUT = p.Definition.Name
Thanks a lot Kulkul, the solution is working for number parameters!
@Kulkul the solutions is not working for text parameter. You know why this could happen?
1 Like
Hi @Raul.Galdran ,
this should handle all parameter types :
import clr
# Import RevitAPI
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import FamilyManager
# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
s = doc.FamilyManager.CurrentType
pl = doc.FamilyManager.Parameters
Name_Parameter = IN[0]
p = [i for i in pl if i.Definition.Name == Name_Parameter][0]
try:
v = s.AsString(p)
except:
try :
v = s.AsValueString(p)
except :
try:
v = s.AsDouble(p)
except:
v = s.AsInteger(p)
OUT = v
1 Like
I tried your code and at least for me doesn’t work with Length Parameters:
The one up is yours. And the one down is mine, yesterday i managed to find a way. Still needs a little bit of work so it can read all type of parameter but at least can read text and length parameters. I’ll like also integer and number but i think is just adding a little bit more of code.
i copy the final code, is a little bit bungler but works:
import clr
# Import RevitAPI
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
pl = doc.FamilyManager.Parameters
s = doc.FamilyManager.CurrentType
mm=304.8
Name_Parameter = IN[0]
for p in pl:
a = p.Definition.Name
if a == Name_Parameter:
paramType = p.Definition.ParameterType
if paramType.ToString() == "Length":
OUT = s.AsDouble(p)*mm
else:
OUT = s.AsString(p)
Thanks all for your ideas and your time
My bad @Raul.Galdran , when the parameter type is not right for the query method, I thought it would return an exception but it just returns “None”…
So here’s an alternative to make sure all parameter types are handeled :
import clr
# Import RevitAPI
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
s = doc.FamilyManager.CurrentType
pl = doc.FamilyManager.Parameters
Name_Parameter = IN[0]
p = [i for i in pl if i.Definition.Name == Name_Parameter][0]
UIunits = p.DisplayUnitType
vals = s.AsString(p), UnitUtils.ConvertFromInternalUnits(s.AsDouble(p),UIunits), s.AsInteger(p)
v = [v for v in vals if v != None]
OUT = v
I also added some code to get the current UI units in your family document and do the convetion automatically. That way all units will be handeled automatically.
1 Like
@Mostafa_El_Ayoubi
I tried your last code and still doesn’t read text neither integer. I’ve modified " in a really crappy way" but now works with every Parameter Type i’ve tried. ( Text, integer, number, area, length, and several units more), all returned the value from the parameter.
The problem was (UIunits = p.DisplayUnitType) in text/integer…!
I copy the final code:
import clr
# Import RevitAPI
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
s = doc.FamilyManager.CurrentType
pl = doc.FamilyManager.Parameters
Name_Parameter = IN[0]
p = [i for i in pl if i.Definition.Name == Name_Parameter][0]
try:
UIunits = p.DisplayUnitType
vals = UnitUtils.ConvertFromInternalUnits(s.AsDouble(p),UIunits), s.AsInteger(p)
v = [v for v in vals if v != None][0]
OUT = v
except Exception:
vals = s.AsString(p), s.AsInteger(p)
v = [v for v in vals if v != None][0]
OUT = v
Thanks again for your time and solutions
1 Like