Code nhóm C#
1 Thêm class
Code:
public static List<List<BlockReference>> GroupByDist(ref List<BlockReference> brs, double distance)
{
var brss = new List<List<BlockReference>>();
var bsdrawn = new List<BlockReference>();
foreach (var br in brs)
{
if (bsdrawn.Contains(br))
continue;
var matchbrs = new List<BlockReference>() { br };
var bs = brs.Except(bsdrawn).Where(x => matchbrs.Any(x1 => x.Position.DistanceTo(x1.Position) < distance)).ToList();
while (bs.Count > 0)
{
matchbrs.AddRange(bs);
bsdrawn.AddRange(bs);
bs = brs.Except(bsdrawn).Where(x => matchbrs.Any(x1 => x.Position.DistanceTo(x1.Position) < distance)).ToList();
}
brss.Add(matchbrs);
}
brs = brs.Except(bsdrawn).ToList();
return brss;
}Code nhóm VB
1 Thêm class
Code:
<Extension> Public Function GroupByDist(ByRef brs As List(Of BlockReference), ByVal distance As Double) As List(Of List(Of BlockReference)) Dim brss = New List(Of List(Of BlockReference)) Dim bsdrawn = New List(Of BlockReference) For Each br In brs If bsdrawn.Contains(br) Then Continue For Dim matchbrs = New List(Of BlockReference) From {br} Dim bs = brs.Except(bsdrawn).Where(Function(x) matchbrs.Any(Function(x1) x.Position.DistanceTo(x1.Position) < distance)).ToList() Do While bs.Count > 0 matchbrs.Add(bs) bsdrawn.AddRange(bs) bs = brs.Except(bsdrawn).Where(Function(x) matchbrs.Any(Function(x1) x.Position.DistanceTo(x1.Position) < distance)).ToList() Loop brss.Add(matchbrs) Next brs = brs.Except(bsdrawn).ToList() Return brss End Function
Link solution
Nhóm AutoCAD dotNet
Link tham gia nhóm Zalo: http://dnz.lisp.vn
---------------------------------------------------------------------------------------------
Mọi thông tin xin liên hệ Fanpage AutoLISP Thật là đơn giản!
Cảm ơn bạn đã theo dõi!
Không có nhận xét nào:
Đăng nhận xét