revit二次开发——建连续刚构桥2(带平纵曲线)

来源:建筑界编辑:黄子俊发布时间:2020-03-22 19:39:17

[摘要] 上一个方法对于直线的连续刚构桥行得通,但对于有平纵曲线的连续刚构桥还是行不通,这里主要是族的原因,因为带平纵曲线的连续刚构桥每一

上一个方法对于直线的连续刚构桥行得通,但对于有平纵曲线的连续刚构桥还是行不通,这里主要是族的原因,因为带平纵曲线的连续刚构桥每一个节段都可以算作一个异形结构。人工建死族的话,耗时耗力,而且效果还不好。这就需要用到二次开发来解决。

首先得明确模型要达到怎样的一个效果,需要用到哪些数学知识。

这里要达到的效果:

1)梁段截面垂直于路线的平曲线,这点很重要,因为很多人直接用空间曲线来建模,另外用上自适应构件族,这直接导致截面与空间曲线垂直,而不是与平曲线垂直

2)要满足竖曲线的要素,就需要将截面沿z方向移动到竖向位置

3)要想达到上面的效果,首先第1点,通过自适应构件族里的通过点来生成线,每个点是梁段截面中心点的位置,然后把截面族放到相应点的位置,并旋转截面,使截面和每点的切线垂直,然后将移动到三维空间点位,最后生成Form结构。

具体实现的方法的类:

 class CreatJM { /// <summary> /// 创建截面 /// </summary> /// <param name="familyDoc"></param> /// <param name="revitDoc"></param> /// <param name="revitApp"></param> /// <param name="i"></param> /// <param name="filePath1"></param> /// <param name="filePath2"></param> /// <returns></returns> public Family CreatFamiliesItem(Document familyDoc, Document revitDoc, Application revitApp, int i, string filePath1, string filePath2) { FamilyInstance famIns1; FamilyInstance famIns2; FamilyInstance famIns3; FamilyInstance famIns4; Plane plane1 = new Plane(); Plane plane2 = new Plane(); using (Transaction transaction1 = new Transaction(familyDoc)) { transaction1.Start("主题"); //在下面添加主要代码内容 #region 平曲线 ReferencePointArray refPointArray = new ReferencePointArray(); for (int j = 0; j < ListData.ListXYZ_X.Count; j++) { ReferencePoint referencePoint = familyDoc.FamilyCreate.NewReferencePoint(new XYZ(ListData.ListXYZ_X[j], ListData.ListXYZ_Y[j], 0)); //在体量族里建成空间参照点 refPointArray.Append(referencePoint); } CurveByPoints curve = familyDoc.FamilyCreate.NewCurveByPoints(refPointArray); //在体量族里将空间参照点串成空间曲线 #endregion #region 纵曲线 ReferencePointArray refPointArray2 = new ReferencePointArray(); for (int j = 0; j < ListData.ListXYZ_X.Count; j++) { ReferencePoint referencePoint2 = familyDoc.FamilyCreate.NewReferencePoint(new XYZ(ListData.ListXYZ_X[j], ListData.ListXYZ_Y[j], ListData.ListXYZ_Z[j])); //在体量族里建成空间参照点 refPointArray2.Append(referencePoint2); } CurveByPoints curve2 = familyDoc.FamilyCreate.NewCurveByPoints(refPointArray2); //在体量族里将空间参照点串成空间曲线 //ReferenceArray path2 = new ReferenceArray(); //path2.Append(curve2.GeometryCurve.Reference); #endregion famIns1 = LocationFamilyInstance(familyDoc, filePath1, curve2.GetPoints().get_Item(i).Position, (curve.GeometryCurve as HermiteSpline).Tangents[i], i); famIns2 = LocationFamilyInstance(familyDoc, filePath1, curve2.GetPoints().get_Item(i + 1).Position, (curve.GeometryCurve as HermiteSpline).Tangents[i + 1], i + 1); famIns3 = LocationFamilyInstance2(familyDoc, filePath2, curve2.GetPoints().get_Item(i).Position, (curve.GeometryCurve as HermiteSpline).Tangents[i], i); famIns4 = LocationFamilyInstance2(familyDoc, filePath2, curve2.GetPoints().get_Item(i + 1).Position, (curve.GeometryCurve as HermiteSpline).Tangents[i + 1], i + 1); plane1 = new Plane((curve.GeometryCurve as HermiteSpline).Tangents[i], curve.GetPoints().get_Item(i).Position); plane2 = new Plane((curve.GeometryCurve as HermiteSpline).Tangents[i + 1], curve.GetPoints().get_Item(i + 1).Position); familyDoc.Delete(curve.Id); familyDoc.Delete(curve2.Id); refPointArray.Clear(); refPointArray2.Clear(); transaction1.Commit(); } using (Transaction transaction2 = new Transaction(familyDoc)) { transaction2.Start("主题"); //在下面添加主要代码内容 ReferenceArray profiles0 = GetReferenceArrayFromFamilyInstance(familyDoc, famIns1, plane1); ReferenceArray profiles1 = GetReferenceArrayFromFamilyInstance(familyDoc, famIns2, plane2); ReferenceArray profiles2 = GetReferenceArrayFromFamilyInstance(familyDoc, famIns3, plane1); ReferenceArray profiles3 = GetReferenceArrayFromFamilyInstance(familyDoc, famIns4, plane2); ReferenceArrayArray profilesArray = new ReferenceArrayArray(); profilesArray.Append(profiles0); profilesArray.Append(profiles1); Form form = familyDoc.FamilyCreate.NewLoftForm(true, profilesArray); ReferenceArrayArray profilesArray2 = new ReferenceArrayArray(); profilesArray2.Append(profiles2); profilesArray2.Append(profiles3); Form form2 = familyDoc.FamilyCreate.NewLoftForm(false, profilesArray2); string paramName ="材质"; familyDoc.FamilyManager.AddParameter(paramName, BuiltInParameterGroup.PG_MATERIALS, ParameterType.Material, true); transaction2.Commit(); Family loadedFamily = familyDoc.LoadFamily(revitDoc, new ProjiectFamLoadOption()); return loadedFamily; } } /// <summary> /// 得到截面的referenceArray /// </summary> /// <param name="familyDoc"></param> /// <param name="famIns"></param> /// <param name="plane"></param> /// <returns></returns> private ReferenceArray GetReferenceArrayFromFamilyInstance(Document familyDoc, FamilyInstance famIns, Plane plane) { ReferenceArray profilesArray = new ReferenceArray(); Options opt = new Options(); IList<Curve> curves1 = new List<Curve>(); GeometryElement e = famIns.get_Geometry(opt); foreach (GeometryObject obj in e) { GeometryInstance geoInstance = obj as GeometryInstance; GeometryElement geoElement = geoInstance.GetInstanceGeometry(); foreach (GeometryObject obj2 in geoElement) { if (obj2.GetType().ToString() =="Autodesk.Revit.DB.Line"|| obj2.GetType().ToString() =="Autodesk.Revit.DB.Arc") { Curve curve = obj2 as Curve; ModelCurve modelcurve = familyDoc.FamilyCreate.NewModelCurve(curve, SketchPlane.Create(familyDoc, plane)); profilesArray.Append(modelcurve.GeometryCurve.Reference); } } } return profilesArray; } /// <summary> /// 把外截面族准确的放在相应位置 /// </summary> /// <param name="familyDoc"></param> /// <param name="filePath"></param> /// <param name="location"></param> /// <param name="normal"></param> /// <param name="i"></param> /// <returns></returns> private FamilyInstance LocationFamilyInstance(Document familyDoc, string filePath, XYZ location, XYZ normal, int i) { FamilySymbol familySymbol = null; bool modelCurveZhu = familyDoc.LoadFamilySymbol(filePath, System.IO.Path.GetFileNameWithoutExtension(filePath), out familySymbol); //这里的族一定要有类型才行 familySymbol.Activate(); //激活族类型 List<Autodesk.Revit.Creation.FamilyInstanceCreationData> list = new List<Autodesk.Revit.Creation.FamilyInstanceCreationData>(); list.Add(new Autodesk.Revit.Creation.FamilyInstanceCreationData(location, familySymbol, StructuralType.NonStructural)); var familyInstancesIds = familyDoc.FamilyCreate.NewFamilyInstances2(list); FamilyInstance familyInstance = familyDoc.GetElement(familyInstancesIds.ElementAt(0)) as FamilyInstance; LocationPoint point = familyInstance.Location as LocationPoint; Line line1 = Line.CreateBound(location, new XYZ(location.X, location.Y, (location.Z + 1))); double angle = normal.AngleTo(new XYZ(1, 0, 0)); //Math.Acos(normal.DotProduct(new XYZ(1, 0, 0))); if (normal.CrossProduct(new XYZ(1, 0, 0)).Z < 0) { point.Rotate(line1, angle); } else { point.Rotate(line1, -angle); } IList<Parameter> listParameters = familyInstance.GetParameters("H"); listParameters[0].Set(ListData.List_height[i]); return familyInstance; } /// <summary> /// 把内截面族放到相应位置 /// </summary> /// <param name="familyDoc"></param> /// <param name="filePath"></param> /// <param name="location"></param> /// <param name="normal"></param> /// <param name="i"></param> /// <returns></returns> private FamilyInstance LocationFamilyInstance2(Document familyDoc, string filePath, XYZ location, XYZ normal, int i) { FamilySymbol familySymbol = null; bool modelCurveZhu = familyDoc.LoadFamilySymbol(filePath, System.IO.Path.GetFileNameWithoutExtension(filePath), out familySymbol); //这里的族一定要有类型才行 familySymbol.Activate(); //激活族类型 List<Autodesk.Revit.Creation.FamilyInstanceCreationData> list = new List<Autodesk.Revit.Creation.FamilyInstanceCreationData>(); list.Add(new Autodesk.Revit.Creation.FamilyInstanceCreationData(location, familySymbol, StructuralType.NonStructural)); var familyInstancesIds = familyDoc.FamilyCreate.NewFamilyInstances2(list); FamilyInstance familyInstance = familyDoc.GetElement(familyInstancesIds.ElementAt(0)) as FamilyInstance; LocationPoint point = familyInstance.Location as LocationPoint; Line line1 = Line.CreateBound(location, new XYZ(location.X, location.Y, (location.Z + 1))); double angle = normal.AngleTo(new XYZ(1, 0, 0)); //Math.Acos(normal.DotProduct(new XYZ(1, 0, 0))); if (normal.CrossProduct(new XYZ(1, 0, 0)).Z < 0) { point.Rotate(line1, angle); } else { point.Rotate(line1, -angle); } IList<Parameter> listParameters = familyInstance.GetParameters("Hi1"); listParameters[0].Set(ListData.List_Hi1[i]); IList<Parameter> listParameters1 = familyInstance.GetParameters("Hi5"); listParameters1[0].Set(ListData.List_Hi5[i]); IList<Parameter> listParameters2 = familyInstance.GetParameters("T"); listParameters2[0].Set(ListData.List_t[i]); IList<Parameter> listParameters3 = familyInstance.GetParameters("H"); listParameters3[0].Set(ListData.List_height[i]); return familyInstance; } }

具体效果见视频:
http://v.youku.com/v_show/id_XMjgwMjcwMjY3Ng==.html?spm=a2hzp.8244740.userfeed.5!4~5~5~5!3~5~A

曲线,连续,revit

延展阅读

相关文章


热门资讯推荐