Pārlūkot izejas kodu

mxg:添加空间面积和周长约束

mengxiangge 5 gadi atpakaļ
vecāks
revīzija
42532b1db9

BIN
FWindSoft/Dlls/SAGA.DotNetUtils.dll


BIN
FWindSoft/Dlls/SAGA.RevitUtils.dll


+ 76 - 26
FWindSoft/Saga.PlugIn/CreateSpaceCommand.cs

@@ -38,32 +38,58 @@ namespace LRH.Tool
                 {
                     tran.Start();
 
-                    var space = RevitCore.UIApp.PickElement("请选择空间", new CommonFilter(t => { return t is Space; })) as Space;
+                    //var space = RevitCore.UIApp.PickElement("请选择空间", new CommonFilter(t => { return t is Space; })) as Space;
+                    var space = RevitCore.UIApp.GetSelectedElement() as Space;
                     if (space == null) return Result.Cancelled;
                     SpatialElementBoundaryOptions options = new SpatialElementBoundaryOptions();
-                    options.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.CoreBoundary;
+                    options.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center;
                     var segments = space.GetBoundarySegments(options);
-
+                    double tolerance = RevitCore.App.ShortCurveTolerance;
                     foreach (var segment in segments)
                     {
                         List<XYZ> xyzs = new List<XYZ>();
+                        List<XYZ> xyzs2 = new List<XYZ>();
                         foreach (BoundarySegment boundarySegment in segment)
                         {
-                            var wall = RevitCore.Doc.GetElement(boundarySegment.ElementId) as Wall;
-                            if (wall == null) continue;
-                            var wallCurve = ElementExtension.GetLocationCurve(wall);
-                            var parallelWalls = GetParallelWalls(wall);
-                            var segmentCurve = boundarySegment.GetCurve();
-                            var tessellates = segmentCurve.Tessellate();
-                            foreach (XYZ tessellate in tessellates)
+                            var segmentElement = RevitCore.Doc.GetElement(boundarySegment.ElementId);
+                            if (segmentElement is FamilyInstance fi)
                             {
-                                xyzs.Add(tessellate);
-                                //var project = wallCurve.GetProjectPt(tessellate);
-                                //var verticalVector = (project - tessellate).Normalize();
-                                //var tempXyz = GetOuterXYZ(tessellate, verticalVector, segmentCurve, parallelWalls);
-                                //if (tempXyz != null)
-                                //    xyzs.Add(tempXyz);
+                                foreach (XYZ tessellate in boundarySegment.GetCurve().Tessellate())
+                                {
+                                    xyzs.Add(tessellate);
+                                }
+                                //var point = ElementExtension.GetLocationPoint(fi);
+                                //if(point!=null)
+                                //    xyzs.Add(point);
                             }
+                            else if(segmentElement is Wall wall)
+                            {
+                                var wallCurve = ElementExtension.GetLocationCurve(wall);
+                                var parallelWalls = GetParallelWalls(wall);
+                                var segmentCurve = boundarySegment.GetCurve();
+                                var tessellates = segmentCurve.Tessellate();
+                                foreach (XYZ tessellate in tessellates)
+                                {
+                                    xyzs2.Add(tessellate);
+
+                                    var project = wallCurve.GetProjectPt(tessellate);
+                                    var verticalVector = (project - tessellate).Normalize();
+                                    var tempXyz = GetOuterXYZ(tessellate, verticalVector, segmentCurve, parallelWalls);
+                                    if (tempXyz != null)
+                                        xyzs.Add(tempXyz);
+                                }
+                            }
+                            else
+                            {
+                                foreach (XYZ tessellate in boundarySegment.GetCurve().Tessellate())
+                                {
+                                    xyzs2.Add(tessellate);
+
+                                    xyzs.Add(tessellate);
+                                }
+                            }
+                            
+                            
                         }
 
                         //int count = xyzs.Count;
@@ -73,6 +99,7 @@ namespace LRH.Tool
                         // */
                         //for (int i = 0; i < count; i++)
                         //{
+                        //    if (count < 4) continue;
                         //    var p1 = xyzs[i];
                         //    int j2 = i + 1 >= xyzs.Count ? i + 1 - count : i + 1;
                         //    var p2 = xyzs[j2];
@@ -80,7 +107,7 @@ namespace LRH.Tool
                         //    var p3 = xyzs[j3];
                         //    int j4 = i + 3 >= xyzs.Count ? i + 3 - count : i + 3;
                         //    var p4 = xyzs[j4];
-                        //    if (p1.IsEqual(p2) || p2.IsEqual(p3) || p3.IsEqual(p4))
+                        //    if (p2.IsEqual(p3) || p1.DistanceTo(p2) < tolerance || p3.DistanceTo(p4) < tolerance)
                         //        continue;
                         //    Curve curve1 = Line.CreateBound(p1, p2);
                         //    Curve curve2 = Line.CreateBound(p3, p4);
@@ -90,16 +117,36 @@ namespace LRH.Tool
                         //    xyzs[j3] = intersection;
                         //}
 
-                        if(xyzs.Any())
-                            xyzs.Add(xyzs[0]);
-                        //画线
-                        for (int i = 0; i < xyzs.Count - 1; i++)
+                        //if (xyzs.Any())
+                        //    xyzs.Add(xyzs[0]);
+                        ////画线-外墙
+                        //for (int i = 0; i < xyzs.Count - 1; i++)
+                        //{
+                        //    try
+                        //    {
+                        //        var p1 = xyzs[i];
+                        //        var p2 = xyzs[i + 1];
+                        //        if (p1.IsAlmostEqualTo(p2)||p1.DistanceTo(p2)<tolerance)
+                        //            continue;
+                        //        Curve curve = Line.CreateBound(p1, p2);
+                        //        RevitCore.DocCreater.NewDetailCurve(RevitCore.UIDoc.ActiveView, curve);
+                        //    }
+                        //    catch (Exception e)
+                        //    {
+                        //        Console.WriteLine(e);
+                        //    }
+                        //}
+
+                        if (xyzs2.Any())
+                            xyzs2.Add(xyzs2[0]);
+                        //画线-内墙
+                        for (int i = 0; i < xyzs2.Count - 1; i++)
                         {
                             try
                             {
-                                var p1 = xyzs[i];
-                                var p2 = xyzs[i + 1];
-                                if (p1.IsAlmostEqualTo(p2))
+                                var p1 = xyzs2[i];
+                                var p2 = xyzs2[i + 1];
+                                if (p1.IsAlmostEqualTo(p2) || p1.DistanceTo(p2) < tolerance)
                                     continue;
                                 Curve curve = Line.CreateBound(p1, p2);
                                 RevitCore.DocCreater.NewDetailCurve(RevitCore.UIDoc.ActiveView, curve);
@@ -108,7 +155,7 @@ namespace LRH.Tool
                             {
                                 Console.WriteLine(e);
                             }
-                            
+
                         }
                     }
 
@@ -185,10 +232,13 @@ namespace LRH.Tool
         /// <returns></returns>
         public XYZ GetOuterXYZ(XYZ xyz, XYZ verticalVector, Curve segmentCurve, List<Wall> walls)
         {
-            XYZ outerXyz = null;
+            XYZ outerXyz = xyz;
             double distance = 0;
             foreach (Wall wall in walls)
             {
+                /*
+                 * 注意幕墙,没有底面,直接取原始点xyz
+                 */
                 List<PlanarFace> faces = GetBottomFaces(wall);
                 foreach (PlanarFace face in faces)
                 {

+ 14 - 0
FWindSoft/Saga.PlugIn/ModelCheck/ElementExtend.cs

@@ -110,6 +110,20 @@ namespace Saga.PlugIn.ModelCheck
             return isspace;
         }
         /// <summary>
+        /// 手动删除的空间,仅在明细表中可见
+        /// </summary>
+        /// <param name="space"></param>
+        /// <returns></returns>
+        public static bool IsDeleteSpace(this Space space)
+        {
+            //周长
+            double perimeter = space.Perimeter;
+            //面积
+            double area = space.Area;
+            //空间比较特殊,周长为零就相当于删除
+            return (perimeter.IsZero(ModelCheckConst.SpacePerimeterTolerance)) || (area.IsZero(ModelCheckConst.SpaceAreaTolerance));
+        }
+        /// <summary>
         /// 获取MBI的定位点
         /// </summary>
         /// <param name="element"></param>

+ 5 - 0
FWindSoft/Saga.PlugIn/ModelCheck/ModelCheckConst.cs

@@ -43,5 +43,10 @@ namespace Saga.PlugIn.ModelCheck
         /// 设备本地名称
         /// </summary>
         public readonly static string EquipLocalName = "设备本地名称";
+
+        //最少空间的面积. 0.4m  削减因子: 1
+        public static readonly double SpacePerimeterTolerance = Math.Pow(0.4 * 1000 / 304.8, 2) / 1;
+        //最小空间的周长. 0.4m  削减因子: 1
+        public static readonly double SpaceAreaTolerance = (0.4 * 1000 / 304.8 * 4) / 1;
     }
 }