自适应族

http://blog.csdn.net/joexiongjin/article/details/8476049      如何编程创建自适应族?

自适应族被广大的Revit用户喻为Revit特强大的宝剑之一。关于自适应族的特性请大家看Revit的相关文档。

Revit同时也开放了API来创建自适应构件族,也可以用API来生成自适应构件对象。


Revit提供了AdaptiveComponentFamilyUtils类来处理与创建族相关的功能,提供了10多个方法。具体请看RevitAPI.chm中的说明。

下面列出了如何创建一个自适应构件族的代码。 (摘自RevitAPI.chm)


自适应族的创建于普通族很不一样,可以从代码了解创建步骤和用到的方法。

  1. private void CreateAdaptiveComponentFamily(Document document)  
  2. {  
  3.     // check if this family is an Adaptive Component family  
  4.     if (!(AdaptiveComponentFamilyUtils.IsAdaptiveComponentFamily(document.OwnerFamily))) return;              
  5.     Transaction transaction = new Transaction(document); ;  
  6.     int placementCtr = 1;  
  7.     ReferencePointArray refPointArray = new ReferencePointArray();  
  8.     for (int i = 0; i < 10; i++)  
  9.     {  
  10.         transaction.SetName("Point" + i);  
  11.         transaction.Start();  
  12.         ReferencePoint referencePoint = document.FamilyCreate.NewReferencePoint(new XYZ(i, 0, 0));  
  13.         if (i % 2 == 0)  
  14.         // Even-numbered reference points will be Placement Points  
  15.         {  
  16.             AdaptiveComponentFamilyUtils.MakeAdaptivePoint(document, referencePoint.Id, AdaptivePointType.PlacementPoint);  
  17.             transaction.Commit();  
  18.             AdaptiveComponentFamilyUtils.SetPlacementNumber(document, referencePoint.Id, placementCtr);  
  19.             placementCtr++;  
  20.         }  
  21.         else  
  22.         // Odd-numbered points will be Shape Handle Points  
  23.         {  
  24.             AdaptiveComponentFamilyUtils.MakeAdaptivePoint(document, referencePoint.Id, AdaptivePointType.ShapeHandlePoint);  
  25.             transaction.Commit();  
  26.         }  
  27.         refPointArray.Append(referencePoint);  
  28.     }  
  29.     // Create a curve running through all Reference Points  
  30.     transaction.SetName("Curve");  
  31.     transaction.Start();  
  32.     CurveByPoints curve = document.FamilyCreate.NewCurveByPoints(refPointArray);  
  33.     transaction.Commit();  
  34. }  

如何编程创建自适应构件对象? http://blog.csdn.net/joexiongjin/article/details/8476184


在Revit里面创建普通族实例大家不陌生,用NewFamilyInstance函数即可。这个函数有10来个重载形式,可以创建各种族实例。

在有自适应构件的模型里,我们用RevitLookup查看自适应构件的Location属性为空。(普通族实例的Location属性不会为空,或是一个LocationPoint,或者为LocationLine)。这个开发者带来困惑,我们如何编程创建自适应构件的实例呢?


解决:


Revit给自适应构件提供了另一个类来生成自适应族,以及生成自适应构件对象。

就如何生成自适应族,我写了一篇相关博文,


这里说些如何创建自适应构件对象。AdaptiveComponentInstanceUtils 类提供了10个方法用于创建构件。每一个方法的说明请看RevitAPI.chm文件(Revit2012 以上)

下面的代码演示了如何创建自适应构件实例。


先创建一个对象,然后为每一个点设置坐标。
  1. private void CreateAdaptiveComponentInstance(Document document, FamilySymbol symbol)  
  2. {  
  3.     // Create a new instance of an adaptive component family  
  4.     FamilyInstance instance = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(document, symbol);  
  5.   
  6.     // Get the placement points of this instance  
  7.     IList placePointIds = new List();  
  8.     placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(instance);  
  9.     double x = 0;  
  10.   
  11.     // Set the position of each placement point  
  12.     foreach (ElementId id in placePointIds)  
  13.     {  
  14.         ReferencePoint point = document.GetElement(id) as ReferencePoint;  
  15.         point.Position = new Autodesk.Revit.DB.XYZ(10*x, 10*Math.Cos(x), 0);  
  16.         x += Math.PI/6;  
  17.     }  
  18. }  
revit自适应点的解释    http://wenku.baidu.com/link?url=6kxYBwx09Y_O9mpm5IRUiCKZyS3HG3_hpXhThvXO0llLC-8eb4i2odAEGL9aTyied9lIDxAvMguz5i3C9wbzIdvW_f0tTPUw3iN_lddA4wK

你可能感兴趣的:(revit二次开发)