在revit建模过程中由于管道不平行导致后期添加标注出错,通过手工方式对齐再移动会降低建模效率。
可通过REVIT API 编写宏命令实现一建管道平行,提高建模效率。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| /// <summary> /// 管道平行 /// </summary> public void ElementRote() { Document doc =this.ActiveUIDocument.Document; Autodesk.Revit.UI.Selection.Selection sel =this.ActiveUIDocument.Selection; var eids =sel.GetElementIds(); ElementSet els=new ElementSet(); Line L1=null; Transaction ts1 = new Transaction(doc, "revit"); ts1.Start(); foreach (var eid in eids) { var elem=doc.GetElement(eid); LocationCurve lCurve = elem.Location as LocationCurve; if(L1==null) { //设置基准管道 L1=lCurve.Curve as Line; } Line L2=lCurve.Curve as Line; //计算角度 double deg=GetDegree(L2,L1); //管道旋转 RotateColumn(doc,elem,L2,deg); } ts1.Commit(); }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| /// <summary> /// 计算旋转角度 /// </summary> /// <param name="L1"></param> /// <param name="L2"></param> /// <returns></returns> public double GetDegree (Line L1,Line L2) { XYZ first=L1.GetEndPoint(0); XYZ second=L1.GetEndPoint(1); XYZ third=L2.GetEndPoint(0); XYZ fourth=L2.GetEndPoint(1); var A = Math.Atan2(second.Y - first.Y, second.X - first.X); var B = Math.Atan2(fourth.Y - third.Y, fourth.X - third.X); return (double)(B - A); }
|
1 2 3 4 5 6 7 8 9 10 11 12
| /// <summary> /// 旋转管道 /// </summary> public void RotateColumn(Autodesk.Revit.DB.Document document, Autodesk.Revit.DB.Element element,Line lcenter,double deg) { //设置旋转中心 XYZ point1 = lcenter.GetEndPoint(0); XYZ point2 = new XYZ(point1.X,point1.Y,point1.Z+30); Line axis = Line.CreateBound(point1, point2); //管道旋转 ElementTransformUtils.RotateElement(document, element.Id, axis, deg); }
|