83 lines
3.5 KiB
C#
83 lines
3.5 KiB
C#
using Autodesk.Revit.DB;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace GraphicsStudy
|
|
{
|
|
public static class WallMethod
|
|
{
|
|
/// <summary>
|
|
/// 找到相交的墙
|
|
/// </summary>
|
|
/// <param name="wall"></param>
|
|
/// <returns></returns>
|
|
public static List<ElementId> GetGeoInsterEle(this Wall wall)
|
|
{
|
|
List<ElementId> elemIdList = new List<ElementId>();
|
|
var geo = wall.get_Geometry(new Options());
|
|
foreach (GeometryObject geoObject in geo)
|
|
{
|
|
Solid geoSolid = geoObject as Solid;
|
|
foreach (Face geoFace in geoSolid.Faces)
|
|
{
|
|
var generatingEleId = wall.GetGeneratingElementIds(geoFace).Where(x => !(elemIdList.Contains(x))).ToList();
|
|
generatingEleId.Remove(wall.Id);
|
|
elemIdList.AddRange(generatingEleId);
|
|
}
|
|
}
|
|
return elemIdList;
|
|
}
|
|
/// <summary>
|
|
/// 判断墙是否相连
|
|
/// </summary>
|
|
/// <param name="judgeWall"></param>
|
|
/// <param name="proWall"></param>
|
|
/// <param name="needPoint"></param>
|
|
/// <returns></returns>
|
|
public static bool WallIsConnectedWall(this Wall judgeWall, Wall proWall, out List<XYZ> needPoint)
|
|
{
|
|
bool result = false;
|
|
needPoint = new List<XYZ>();
|
|
Line judgeLocationLine = ((judgeWall.Location as LocationCurve).Curve as Line).SetZ();
|
|
Line proLocationLine = ((proWall.Location as LocationCurve).Curve as Line).SetZ();
|
|
//只对平行的处理
|
|
if (!judgeLocationLine.Direction.IsParallel(proLocationLine.Direction)) return result;
|
|
var judgeGeo = judgeWall.get_Geometry(new Options());
|
|
Face jugeDownFace = GeoMethod.GetGeoEleDownFace(judgeGeo);
|
|
var proGeo = proWall.get_Geometry(new Options());
|
|
Face proDownFace = GeoMethod.GetGeoEleDownFace(proGeo);
|
|
List<Solid> solidList = new List<Solid>();
|
|
//想法一 用布尔运算去测试
|
|
//收集几何体
|
|
double judgeSolidSurfaceArea = 0;
|
|
double prosolidSurfaceArea = 0;
|
|
List<Solid> judgeSolids = GeoMethod.GetSolids(judgeGeo);
|
|
List<Solid> proSolids = GeoMethod.GetSolids(proGeo);
|
|
foreach (var judgeSolid in judgeSolids)
|
|
{
|
|
judgeSolidSurfaceArea += judgeSolid.SurfaceArea;
|
|
solidList.Add(judgeSolid);
|
|
}
|
|
foreach (var proSolid in proSolids)
|
|
{
|
|
prosolidSurfaceArea += proSolid.SurfaceArea;
|
|
solidList.Add(proSolid);
|
|
}
|
|
Solid fuseSolid = solidList.SolidBatchBoolean(BooleanOperationsType.Union);
|
|
if (judgeSolidSurfaceArea + prosolidSurfaceArea - fuseSolid.SurfaceArea > 0)
|
|
{
|
|
result = true;
|
|
//收集中间的两个点
|
|
List<XYZ> pointList = new List<XYZ>() { judgeLocationLine.GetEndPoint(0), judgeLocationLine.GetEndPoint(1), proLocationLine.GetEndPoint(0), proLocationLine.GetEndPoint(1) };
|
|
pointList = pointList.OrderBy(x => x.DotProduct(judgeLocationLine.Direction).Round(3)).ToList();
|
|
needPoint.Add(pointList[1]);
|
|
needPoint.Add(pointList[2]);
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|