|
@@ -46,95 +46,98 @@ namespace SAGA.MBI
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- var fi = ExternalDataWrapper.Current.UiApp.GetSelectedElement() as FamilyInstance;
|
|
|
- var space = fi.GetReferenceSpace();
|
|
|
- string str = "";
|
|
|
- while (true)
|
|
|
- {
|
|
|
- if (space != null)
|
|
|
- {
|
|
|
- List<XYZ> spaceVertex = space.GetBoundaryVertexes().FirstOrDefault();
|
|
|
- if (spaceVertex == null)
|
|
|
- {
|
|
|
- str = "Boundary 为Null";
|
|
|
- break;
|
|
|
- }
|
|
|
+ //var fi = ExternalDataWrapper.Current.UiApp.GetSelectedElement() as FamilyInstance;
|
|
|
+ //var space = fi.GetReferenceSpace();
|
|
|
+ //string str = "",str2="";
|
|
|
+ //while (true)
|
|
|
+ //{
|
|
|
+ // if (space != null)
|
|
|
+ // {
|
|
|
+ // List<XYZ> spaceVertex = space.GetBoundaryVertexes().FirstOrDefault();
|
|
|
+ // if (spaceVertex == null)
|
|
|
+ // {
|
|
|
+ // str = "Boundary 为Null";
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
|
|
|
- var xyz = fi.GetLocationPointMBIXYZ();
|
|
|
- str = "Geometry Intersection Result" + xyz.PointInPolygonByRay(spaceVertex);
|
|
|
+ // var xyz = fi.GetLocationPointMBIXYZ();
|
|
|
+ // str = "Geometry Intersection Result:" + xyz.PointInPolygonByRay(spaceVertex);
|
|
|
|
|
|
+ // str2 = "Geometry2D Intersection Result:" + Geometry2D.InSidePolygon(spaceVertex.Count,
|
|
|
+ // spaceVertex.Select(t => t.ToPointD()).ToArray(), xyz.ToPointD());
|
|
|
|
|
|
- break;
|
|
|
|
|
|
- }
|
|
|
|
|
|
- }
|
|
|
- MessageShowBase.Infomation($"{str}");
|
|
|
-
|
|
|
- //var doc = commandData.View.Document;
|
|
|
- //var spaces = doc.GetSpaces().Where(t => t.IsValidObject).ToList();
|
|
|
- //var fis = doc.GetFamilyInstances().Where(t=>t.IsEquipmentPart()||t.IsEquipment());
|
|
|
- //List<List<List<XYZ>>> spaceVertexes = spaces.Select(t => t.GetBoundaryVertexes()).ToList();
|
|
|
- //List<KeyValuePair<FamilyInstance, XYZ>> keyValuePairs = fis.Select(t => new KeyValuePair<FamilyInstance,XYZ>(t,t.GetLocationPointMBIXYZ())).ToList();
|
|
|
- //List<KeyValuePair<FamilyInstance, XYZ>> keyValuePairs_bak = new List<KeyValuePair<FamilyInstance, XYZ>>();
|
|
|
- //long rtime = 0,gtime = 0;
|
|
|
- //int rcount = 0, gcount = 0;
|
|
|
- //Stopwatch watch = new Stopwatch();
|
|
|
- //#region 使用Revit计算
|
|
|
- //watch.Start();
|
|
|
- //foreach (var pair in keyValuePairs)
|
|
|
- //{
|
|
|
- // FamilyInstance fi = pair.Key;
|
|
|
- // var space=fi.GetReferenceSpace(spaces);
|
|
|
- // if (space != null)
|
|
|
- // {
|
|
|
- // rcount++;
|
|
|
- // keyValuePairs_bak.Add(pair);
|
|
|
// }
|
|
|
+ // break;
|
|
|
+
|
|
|
//}
|
|
|
- //watch.Stop();
|
|
|
- //rtime = watch.ElapsedMilliseconds;
|
|
|
+ //MessageShowBase.Infomation($"{str}"+"\r\n"+$"{str2}");
|
|
|
+
|
|
|
+ var doc = commandData.View.Document;
|
|
|
+ var spaces = doc.GetSpaces().Where(t => t.IsValidObject).ToList();
|
|
|
+ var fis = doc.GetFamilyInstances().Where(t => t.IsEquipmentPart() || t.IsEquipment());
|
|
|
+ List<List<List<XYZ>>> spaceVertexes = spaces.Select(t => t.GetBoundaryVertexes()).ToList();
|
|
|
+ List<KeyValuePair<FamilyInstance, XYZ>> keyValuePairs = fis.Select(t => new KeyValuePair<FamilyInstance, XYZ>(t, t.GetLocationPointMBIXYZ())).ToList();
|
|
|
+ List<KeyValuePair<FamilyInstance, XYZ>> keyValuePairs_bak = new List<KeyValuePair<FamilyInstance, XYZ>>();
|
|
|
+ long rtime = 0, gtime = 0;
|
|
|
+ int rcount = 0, gcount = 0;
|
|
|
+ Stopwatch watch = new Stopwatch();
|
|
|
+ #region 使用Revit计算
|
|
|
+ watch.Start();
|
|
|
+ foreach (var pair in keyValuePairs)
|
|
|
+ {
|
|
|
+ FamilyInstance fi = pair.Key;
|
|
|
+ var space = fi.GetReferenceSpace(spaces);
|
|
|
+ if (space != null)
|
|
|
+ {
|
|
|
+ rcount++;
|
|
|
+ keyValuePairs_bak.Add(pair);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ watch.Stop();
|
|
|
+ rtime = watch.ElapsedMilliseconds;
|
|
|
|
|
|
- //#endregion
|
|
|
+ #endregion
|
|
|
|
|
|
- //#region 使用Geomety计算
|
|
|
+ #region 使用Geomety计算
|
|
|
|
|
|
- //List<List<XYZ>> spaceBorderVertexes = spaceVertexes.Select(t => t.FirstOrDefault()).ToList();
|
|
|
- //watch.Reset();
|
|
|
- //watch.Start();
|
|
|
+ List<List<XYZ>> spaceBorderVertexes = spaceVertexes.Select(t => t.FirstOrDefault()).ToList();
|
|
|
+ watch.Reset();
|
|
|
+ watch.Start();
|
|
|
|
|
|
- //foreach (var pair in keyValuePairs)
|
|
|
- //{
|
|
|
- // XYZ xyz = pair.Value;
|
|
|
- // double z = xyz.Z;
|
|
|
- // var point = xyz.ToPointD();
|
|
|
- // foreach (var spaceVertex in spaceBorderVertexes)
|
|
|
- // {
|
|
|
- // if(spaceVertex==null)continue;
|
|
|
-
|
|
|
- // double minz = spaceVertex.Min(t => t.Z);
|
|
|
- // double maxz = spaceVertex.Max(t => t.Z);
|
|
|
- // //if (z.IsBetween(minz, maxz))
|
|
|
- // {
|
|
|
- // //if(Geometry2D.InSidePolygon(spaceVertex.Count,spaceVertex.Select(t=>t.ToPointD()).ToArray(),point)==1)
|
|
|
- // if (xyz.PointInPolygonByRay(spaceVertex) != -1)
|
|
|
- // {
|
|
|
- // gcount++;
|
|
|
-
|
|
|
- // keyValuePairs_bak.Remove(pair);
|
|
|
- // break;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
- //watch.Stop();
|
|
|
- //gtime = watch.ElapsedMilliseconds;
|
|
|
+ foreach (var pair in keyValuePairs)
|
|
|
+ {
|
|
|
+ XYZ xyz = pair.Value;
|
|
|
+ double z = xyz.Z;
|
|
|
+ var point = xyz.ToPointD();
|
|
|
+ foreach (var spaceVertex in spaceBorderVertexes)
|
|
|
+ {
|
|
|
+ if (spaceVertex == null) continue;
|
|
|
+
|
|
|
+ double minz = spaceVertex.Min(t => t.Z);
|
|
|
+ double maxz = spaceVertex.Max(t => t.Z);
|
|
|
+ //if (z.IsBetween(minz, maxz))
|
|
|
+ {
|
|
|
+ if(Geometry2D.InSidePolygon(spaceVertex.Count,spaceVertex.Select(t=>t.ToPointD()).ToArray(),point)!=2)
|
|
|
+ //if (xyz.PointInPolygonByRay(spaceVertex) != -1)
|
|
|
+ {
|
|
|
+ gcount++;
|
|
|
+
|
|
|
+ keyValuePairs_bak.Remove(pair);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ watch.Stop();
|
|
|
+ gtime = watch.ElapsedMilliseconds;
|
|
|
|
|
|
- //#endregion
|
|
|
+ #endregion
|
|
|
|
|
|
- //MessageShow.Infomation($"Revit计算耗时{rtime},共识别出{rcount}个空间" + "\r\n" +
|
|
|
- // $"Geometry计算耗时{gtime},共识别出{gcount}个空间"+"\r\n"+
|
|
|
- // $"{string.Join(",",keyValuePairs_bak.Select(t=>t.Key.Id))}");
|
|
|
+ MessageShow.Infomation($"Revit计算耗时{rtime},共识别出{rcount}个空间" + "\r\n" +
|
|
|
+ $"Geometry计算耗时{gtime},共识别出{gcount}个空间" + "\r\n" +
|
|
|
+ $"{string.Join(",", keyValuePairs_bak.Select(t => t.Key.Id))}");
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|