FamilyIstance.GetFamily error Duct categories

Can anyone help me to resolve this error
of familyInstance.getfamily for the duct categories? I attach
the script.Script Duct.dyn (28.4 KB)