Get Parameter from Current Family [FamilyEditor]

Hi all,

I found the Python script below from @Mostafa_El_Ayoubi.
https://forum.dynamobim.com/t/revit-family-parameters-value-family-editor/8499/7?u=mjb-online

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

It is exactly what i was looking for, but i doesn’t seem to update when running it for the second time.
Any ideas?

Hi @MJB-online ,

Are you in the family editor?

Yes i am (see topic title :slightly_smiling_face:)

1 Like

What revit version you are using now ?

I use Revit 2019 and Dynamo 2.0.4 as a test environment

can help me send a dynamo dyn file you are running in to forum ?

Haha my bad.

1 Like

Tested it working in revit 2021


testttt.dyn (3.9 KB)
rac_basic_sample_family.rfa (344 KB)

Hi @chuongmep,

What happens if you adjust the family parameter and run the script again? The first time it goes well for me, but when the parameters are updated, the python code retains the old value

you can try add flag true false if problem still cause, toggle true false to update value

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

flag = IN[1]
Name_Parameter = IN[0]
if flag:
	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
else: OUT = None

testttt.dyn (5.3 KB)

2 Likes

Thank you very much.
I was hoping there would be a solution without a toggle, but if not I’ll try this solution

1 Like

I know an event can help you is IUpdate in Revit API but I think it is complex to apply in your case, but you can research it. IUpdater Interface

1 Like