|
用API创建族的时候,常常用到创建参考面,可以用 Autodesk.Create.Document.FamilyCreate.NewReferencePlane()方法和NewReferencePlane2() 方法创建. 这里我们只谈第一个函数。因为它有一个向量参数的含义比较模糊。方法二需要指定参考面上的三个点即可。
NewReferencePlane定义如下:
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; ">[c-sharp] view plaincopy</span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; ">public ReferencePlane NewReferencePlane( </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> XYZ bubbleEnd, </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> XYZ freeEnd, </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> XYZ cutVec, </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> View pView </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; ">) </span>
复制代码 他可以用两个点外加一个向量在指定的视图上创建参考面。
这里第三个参数的向量在RevitAPI.chm中的解释是:The cut vector apply to reference plane, should perpendicular to the vector (bubbleEnd-freeEnd). cut vector 的含义好像不是一个专有名词,无法找到解释。这个cutVec向量参数的含义是这个向量必须在需要创建的参考平面的里面,相当于切线向量吧。而不是需要创建参考面的法向量。这一点最容易误解。
知道这个含义就简单了。
例如我们想创建一个水平面上45度斜参考平面。如下参考面。
可以用下面的代码。
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; ">[c-sharp] view plaincopy</span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; ">using System; </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; ">using System.Collections.Generic; </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; ">using System.Text; </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; ">using System.Windows.Forms; </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; ">using Autodesk.Revit .DB; </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; ">using Autodesk.Revit.UI; </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; ">using Autodesk.Revit .ApplicationServices; </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; ">using Autodesk.Revit.Attributes ; </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)] </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> [RegenerationAttribute(Autodesk.Revit.Attributes.RegenerationOption.Manual)] </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; ">public class RevitCommand : IExternalCommand </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; ">{ </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements) </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> { </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> UIApplication app = commandData.Application; </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> Document doc = app.ActiveUIDocument.Document; </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> Transaction trans = new Transaction(doc, "ExComm"); </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> trans.Start(); </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> // create the reference plane. </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> XYZ bubbleEnd = new XYZ(5,10,0); </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> XYZ freeEnd = new XYZ(10,5,0); </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> XYZ cutNorm = new XYZ(0,0,1); </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> ReferencePlane rp1 = doc.FamilyCreate.NewReferencePlane(bubbleEnd, freeEnd, cutNorm, doc.ActiveView); </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> rp1.Name = "my test43"; </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> trans.Commit(); </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> return Result.Succeeded ; </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; "> } </span>
- <span style="color: rgb(105, 105, 105); font-family: 'Microsoft Yahei', Simsun; ">} </span>
复制代码 转自:http://blog.csdn.net/joexiongjin/article/details/6202804 作者:叶雄进
|
|