revit二次开发之参数化族类型

创建参数化族类型(脚手杆长度)

因为我是用的族为构建组,并非系统族,在网上并没有找到适合构建族的方法,所以用的方法比较笨

大概方法为自己规定一套命名方法,然后遍历族类型找到同名族类型,若没找到,则先进行复制再参数化,所以要两个方法配合使用才能确保返回需求;

 

 1 protected static FamilySymbol Symbols(Document document, Family family, double railLength,string scaffoldName)
 2 {
 3     FamilySymbol railType = null;
 4     int count = 1;
 5 
 6     foreach (ElementId railId in family.GetFamilySymbolIds()) //遍历每个族类型的族ID
 7     {
 8         railType = document.GetElement(railId) as FamilySymbol; //获取族类型
 9         if (railType != null)
10         {
11             if (railType.Name == scaffoldName + "(" + railLength + "mm" + ")")
12             {
13                 return railType;  //返回需求的族类型
14             }
15             if (count == family.GetFamilySymbolIds().Count())  //当不存在时重新创建族类型
16             {
17                 Transaction transaction = new Transaction(document);
18                 transaction.Start("开始创建新参数化");
19 
20                 ElementType elementType = railType.Duplicate(scaffoldName + "(" + railLength + "mm" + ")"); //复制
21                 ParameterSet Parameters = elementType.Parameters;  //参数集合
22                 foreach (Autodesk.Revit.DB.Parameter lengthParameter in Parameters)
23                 {
24                     if (lengthParameter.Definition.Name == "杆长")
25                     {
26                         if (!lengthParameter.IsReadOnly) //参数是否只读
27                         {
28                             lengthParameter.Set((railLength) / 304.8);
29                         }
30 
31                     }
32 
33                 }
34                 transaction.Commit();
35                 return null;
36             }
37 
38         }
39         count++;
40     }
41 
42     return null;
43 }
 1 public static FamilySymbol ReturnSymbols(Document document, Family family, double Length, string scaffoldName)
 2 {
 3     FamilySymbol railSymbol = Symbols(document, family, Length, scaffoldName);
 4 
 5     if (railSymbol == null)  //此处若运行说明并没有直接找到而是进行了参数化
 6     {
 7         railSymbol = Symbols(document, family, Length, scaffoldName);
 8         return railSymbol;
 9     }
10     else
11     {
12         return railSymbol;
13     }
14 }

 

posted @ 2018-10-25 16:24  邢韬  阅读(2334)  评论(0编辑  收藏  举报