简体   繁体   English

如何从Revit-api C#中的Revit文档向Revit系列元素添加参数

[英]How to add parameters to a revit family element from revit document in revit-api c#

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. 我正在一个项目中,我需要在revit文档上加载管道配件(弯管)revit系列并将其共享参数更新为类型参数。

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. 问题是我无法从revit文档访问耦合参数。

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. 如果我手动尝试,则只有在双击折弯族时才能访问耦合参数,这将打开revit族文件。 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. 我如何通过编程方式从revit文档中完成将参数添加到revit系列元素的上述任务。

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 ie the parameter with the name "subFamilyName". 我无法获得结果,我也想仅在耦合族上设置参数“ JP”,即名称为“ subFamilyName”的参数。

Yes, you can achieve the same programmatically as well via the API. 是的,您也可以通过API以编程方式实现相同目的。

Just as you need to open the family file in the manual approach, you can call the EditFamily method to do so in the API: 就像您需要以手动方式打开族文件一样,您可以在API中调用EditFamily方法来这样做:

https://apidocs.co/apps/revit/2019/56e636ee-5008-0ee5-9d6c-5f622dedfbcb.htm https://apidocs.co/apps/revit/2019/56e636ee-5008-0ee5-9d6c-5f622dedfbcb.htm

Check out various posts by The Building Coder mentioning this method, eg, Modifying, Saving and Reloading Families . 查看建筑编码员提到此方法的各种帖子,例如, 修改,保存和重新加载家庭

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM