《revit的api编程2》由会员分享,可在线阅读,更多相关《revit的api编程2(69页珍藏版)》请在金锄头文库上搜索。
1、Revit Family .NET API: Create Frustum of Cone in Family Document Revit .NET has provided the family API for several versions. We did not really address it in the past. In this series of posts, we are going to explore the Revit family .NET API and provide nice sample code and good analysis as usual.L
2、ets create a Frustum of Cone solid into a family document. Here we go.public static ElementId CreateFrustumOfCone(RvtDocument famDoc, XYZ bottomCenter, double bottomRadius, double topRadius, double height) ElementId ret;CurveArray bottomProfile = new CurveArray();Plane plane = new Plane(XYZ.BasisZ,
3、bottomCenter);Arc arc1 = famDoc.Application.Create.NewArc(plane, bottomRadius, 0.0, Math.PI);Arc arc2 = famDoc.Application.Create.NewArc(plane, bottomRadius, Math.PI, Math.PI * 2);bottomProfile.Append(arc1);bottomProfile.Append(arc2);SketchPlane sketchPlane = famDoc.FamilyCreate.NewSketchPlane(plane
4、);CurveArray topProfile = new CurveArray();plane = new Plane(XYZ.BasisZ, new XYZ(bottomCenter.X, bottomCenter.Y, bottomCenter.Z + height);arc1 = famDoc.Application.Create.NewArc(plane, topRadius, 0.0, Math.PI);arc2 = famDoc.Application.Create.NewArc(plane, topRadius, Math.PI, Math.PI * 2);topProfile
5、.Append(arc1);topProfile.Append(arc2);Blend solid = famDoc.FamilyCreate.NewBlend(true,topProfile,bottomProfile,sketchPlane);ret = solid.Id;return ret; public static void TestFrustumOfCone(UIApplication uiapp) RvtDocument famDoc = GetOpenOrCreateFamilyTestDoc(uiapp);using (Transaction tr = new Transa
6、ction(famDoc, “FrustumOfCone“)tr.Start();CreateFrustumOfCone(famDoc, new XYZ(25, 30, 0), 5, 2, 10);tr.Commit(); Here is how the newly created Frustum of Cone looks like in the Revit family document.页码,1/24RevitNetAddinWizard CurveArray bottomProfile = new CurveArray();Plane plane = new Plane(XYZ.Bas
7、isZ, bottomCenter);Arc arc1 = famDoc.Application.Create.NewArc(plane, radius, 0.0, Math.PI);Arc arc2 = famDoc.Application.Create.NewArc(plane, radius, Math.PI, Math.PI * 2);bottomProfile.Append(arc1);bottomProfile.Append(arc2);SketchPlane sketchPlane = famDoc.FamilyCreate.NewSketchPlane(plane);Curve
8、Array topProfile = new CurveArray();plane = new Plane(XYZ.BasisZ, new XYZ(bottomCenter.X, bottomCenter.Y, bottomCenter.Z + height);arc1 = famDoc.Application.Create.NewArc(plane, 1e- 3, 0.0, Math.PI);arc2 = famDoc.Application.Create.NewArc(plane, 1e- 3, Math.PI, Math.PI * 2);topProfile.Append(arc1);t
9、opProfile.Append(arc2);Blend solid = famDoc.FamilyCreate.NewBlend(true,页码,2/24RevitNetAddinWizard ret = solid.Id;return ret; public static void TestCreateCone(UIApplication uiapp) RvtDocument famDoc = GetOpenOrCreateFamilyTestDoc(uiapp);using (Transaction tr = new Transaction(famDoc, “CreateCone“)tr
10、.Start();CreateCone(famDoc, new XYZ(25, 0, 0), 5, 10);tr.Commit(); Here is how the newly created Cone looks like in the Revit family document.Revit Addin Wizard (RevitAddinWizard) provides various wizards, coders and widgets to help program Revit addins. It can be downloaded from the Download link a
11、t the bottom of the blog index page.Sep 17, 2013 3:45:35 PM Comment 0Reblog It 009/15/2013 Revit Family .NET API: Create Cylinder in Family Document 页码,3/24RevitNetAddinWizard CurveArrArray curveArrArr = new CurveArrArray();CurveArray curveArr1 = new CurveArray();curveArrArr.Append(curveArr1);Plane
12、plane = new Plane(XYZ.BasisZ, bottomCenter);Arc arc1 = famDoc.Application.Create.NewArc(plane, radius, 0.0, Math.PI);Arc arc2 = famDoc.Application.Create.NewArc(plane, radius, Math.PI, Math.PI * 2);curveArr1.Append(arc1);curveArr1.Append(arc2);Extrusion solid = famDoc.FamilyCreate.NewExtrusion(true,
13、curveArrArr,famDoc.FamilyCreate.NewSketchPlane(plane),height);ret = solid.Id;return ret; public static void TestCreateCylinder(UIApplication uiapp) RvtDocument famDoc = GetOpenOrCreateFamilyTestDoc(uiapp);using (Transaction tr = new Transaction(famDoc, “CreateCylinder“)tr.Start();CreateCylinder(famD
14、oc, new XYZ(10, 0, 0), 5, 10);tr.Commit(); Here is how the newly created cylinder looks like in the Revit family document.页码,4/24RevitNetAddinWizard string libPath = CachedDoc.Application.GetLibraryPaths()“Imperial Library“;页码,5/24RevitNetAddinWizard CachedDoc.LoadFamilySymbol(rfaFullName, “6 x 8“);
15、CachedDoc.LoadFamilySymbol(rfaFullName, “8 x 10“);tran1.Commit(); Before the code was run, our test Revit model had only a few default architectural Rectangular Columns, as shown by the following screenshot:After the code was run, we found the two column symbols of the Wood Timber Column family as e
16、xplicitly specified in the code had been successfully loaded into the current document and they were available to use right way, as clearly shown by another screenshot below.页码,6/24RevitNetAddinWizard string famTemplatePath = app.FamilyTemplatePath;string templateFullName = Path.Combine(famTemplatePath, templateName + “.rft“);页码,7/24RevitNetAddinWizard famDoc.SaveAs(fileNameToSave);return famDoc; public static RvtDocument GetOpenOrCreateFamilyTestDoc(UIApplication uia