Browse Source

xls:增加定位点检查

xulisong 6 years ago
parent
commit
daaa3e8e75
2 changed files with 140 additions and 1 deletions
  1. 1 1
      MBI/SAGA.GplotDrawData/DBView/VerticalPipeGraphView.cs
  2. 139 0
      MBI/SAGA.MBI/TestCommand.cs

+ 1 - 1
MBI/SAGA.GplotDrawData/DBView/VerticalPipeGraphView.cs

@@ -56,7 +56,7 @@ namespace SAGA.GplotDrawData
                     var existPipe = pipes.FirstOrDefault(p => p.FloorId == floorId);
                     if (existPipe != null)
                     {
-                        existPipe.Name = existPipe.Name + "," + verData.Id;
+                        existPipe.Name = existPipe.Name + "," + verData.Display;
                         continue;
                     }
                     VPipe pipe = new VPipe();

+ 139 - 0
MBI/SAGA.MBI/TestCommand.cs

@@ -4,6 +4,7 @@ using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows.Media;
 using Autodesk.Revit.Attributes;
 using Autodesk.Revit.DB;
 using Autodesk.Revit.DB.Plumbing;
@@ -22,6 +23,7 @@ using SAGA.RevitUtils;
 using SAGA.RevitUtils.Extends;
 using SAGA.RevitUtils.MEP;
 using WPfPointInfo;
+using Color = Autodesk.Revit.DB.Color;
 
 namespace SAGA.MBI
 {
@@ -155,4 +157,141 @@ namespace SAGA.MBI
             }
         }
     }
+
+    /// <summary>
+    /// 管道系统类型
+    /// </summary>
+    [Transaction(TransactionMode.Manual)]
+    [Regeneration(RegenerationOption.Manual)]
+    public class CheckLocationCommand : ExternalCommand, IExternalCommandAvailability
+    {
+        public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
+        {
+            try
+            {
+                var pickElement = ExternalDataWrapper.Current.UiApp.PickElement("请选择设备", new EquipmentFilter()) as FamilyInstance;
+                if (pickElement == null)
+                {
+                    return Result.Succeeded;
+                }
+                using (Transaction tran = new Transaction(ExternalDataWrapper.Current.Doc, "显示"))
+
+                {
+                    try
+                    {
+                        tran.Start();
+                        var doc = ExternalDataWrapper.Current.Doc;
+                        var s = pickElement.GetLocationPointMBIXYZ();
+                        DirectShape ds = DirectShape.CreateElement(doc,new ElementId(BuiltInCategory.OST_GenericModel));
+                        var solid = CreateSphereAt(s, 1);
+                        ds.AppendShape(new List<GeometryObject>() { solid });
+                        SetColor(ds,new Color(255, 0, 0));            
+                        tran.Commit();
+                        ExternalDataWrapper.Current.UiApp.SetShowElements(new List<Element>() { ds });
+                    }
+                    catch (Exception ex)
+                    {
+                        MessageShow.Show(ex);
+                        tran.RollBack();
+                    }
+                }
+            }
+            catch (Exception e)
+            {
+                MessageShow.Show(e);
+                return Result.Cancelled;
+            }
+            return Result.Succeeded;
+        }
+
+
+        #region 静态方法
+        /// <summary>
+        /// 替换视图中的图形,来修改颜色
+        /// </summary>
+        public static void SetColor( Element elem, Color color, View view = null,
+            int transparency = 0)
+        {
+            var ogs = new OverrideGraphicSettings();
+
+
+            #region 表面填充图案
+
+            //可见
+            ogs.SetProjectionFillPatternVisible(true);
+            //颜色
+            ogs.SetProjectionFillColor(color);
+            //透明度
+            ogs.SetSurfaceTransparency(transparency);
+
+            #endregion
+
+            #region 截面填充图案
+
+            //可见
+            ogs.SetCutFillPatternVisible(true);
+            //颜色
+            ogs.SetCutFillColor(color);
+            //填充图案
+            #endregion
+
+            if (view != null)
+            {
+                view.SetElementOverrides(elem.Id, ogs);
+            }
+            else
+            {
+                elem.Document.ActiveView.SetElementOverrides(elem.Id, ogs);
+            }
+        }
+
+        /// <summary>
+        /// 使用指定的球心和半径创建球体
+        /// </summary>
+        static public Solid CreateSphereAt(
+            XYZ centre,
+            double radius)
+        {
+            // 使用标准的全局坐标系创建 Frame
+
+            Frame frame = new Frame(centre,
+                XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ);
+
+            // 创建一个Z轴方向的半圆闭合曲线(注意所有的坐标都是相对全局坐标系的)
+
+            Arc arc = Arc.Create(
+                centre - radius * XYZ.BasisZ,
+                centre + radius * XYZ.BasisZ,
+                centre + radius * XYZ.BasisX);
+
+            Line line = Line.CreateBound(
+                arc.EndPoint(),
+                arc.StartPoint());
+
+            CurveLoop halfCircle = new CurveLoop();
+            halfCircle.Append(arc);
+            halfCircle.Append(line);
+
+            List<CurveLoop> loops = new List<CurveLoop>(1);
+            loops.Add(halfCircle);
+
+            return GeometryCreationUtilities
+                .CreateRevolvedGeometry(
+                    frame, loops, 0, 2 * Math.PI);
+        }
+
+        #endregion
+        public class EquipmentFilter : ISelectionFilter
+        {
+            public bool AllowElement(Element elem)
+            {
+                return elem is FamilyInstance;
+            }
+
+            public bool AllowReference(Reference reference, XYZ position)
+            {
+                return true;
+            }
+        }
+    }
 }