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 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM