I'm working on a project where I need to load pipe fittings (bends) revit families on a revit document and update its shared parameters as type parameters.
I was able to achieve this task since I needed to access the bend family as family instance.
The second part of the requirement is to update the coupling family parameters of the bend as well. The problem is that I'm unable to access the coupling parameter from the revit document.
If I try it manually, the coupling parameter is accessible only when I double click on the bend family, this opens the revit family file. I then can access both the coupling on either side of the bend. How can I achieve the above task of adding parameters to a revit family element from revit document programmatically.
Please guide me.
Thank You in advance.
My Code:
foreach (var item in MainModel.listElement)//List<Element>
{
FamilyInstance elFamInst = item as FamilyInstance;
if (elFamInst.Symbol.FamilyName == "MainFamilyName")//Bend Family
{
ElementId id = item.GetTypeId();
ElementType et = doc.GetElement(id) as ElementType;
Family fam = elFamInst.Symbol.Family;
if (elFamInst.SuperComponent == null)
{
var subElements = elFamInst.GetSubComponentIds();
if (subElements.Count != 0)
{
foreach (var aSubElemId in subElements)
{
var aSubElem = doc.GetElement(aSubElemId);
if (aSubElem is FamilyInstance)
{
FamilyInstance subEl = aSubElem as FamilyInstance;
Family fm = subEl.Symbol.Family;
if(subEl.Symbol.FamilyName == "subFamilyName")//coupling family
{
Document docfamily = doc.EditFamily(fam);
if (null != docfamily && docfamily.IsFamilyDocument == true)
{
FamilyManager familyManager = docfamily.FamilyManager;
using (Transaction trans = new Transaction(docfamily, "param"))
{
trans.Start();
FamilyParameter fp = familyManager.AddParameter("Namess",BuiltInParameterGroup.PG_IDENTITY_DATA,ParameterType.Text, false);
familyManager.Set(fp, "JP");
trans.Commit();
}
}
}
}
}
}
}
}
}
I am unable to achieve the result, also I want the parameter "JP" to be set only on the coupling family i.e. the parameter with the name "subFamilyName".