|
发表于 2010-8-31 22:52:00
|
显示全部楼层
d:\4.gif
代码如下:[code]
Public Sub GetClosedPoint()
Dim ClosedPt As New List(Of Point2d) '保存最近点
Dim db As Database = HostApplicationServices.WorkingDatabase
'获取数据库
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
'获取editor对象
Dim values As TypedValue() = {New TypedValue(DxfCode.Operator, "")}
Dim filter As New SelectionFilter(values)
Dim entOpt As New PromptSelectionOptions
entOpt.MessageForAdding = "请选择要处理的实体"
Dim entRes As PromptSelectionResult = ed.GetSelection(entOpt, filter)
If entRes.Status = PromptStatus.OK Then
Dim sSet As SelectionSet = entRes.Value
Dim pts As New List(Of DBPoint)
Dim plines As New List(Of Polyline)
Using trans As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
Dim btr As BlockTableRecord = trans.GetObject(bt.Item(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
For Each id As ObjectId In sSet.GetObjectIds
Dim ent As Entity = trans.GetObject(id, OpenMode.ForRead)
If TypeOf (ent) Is DBPoint Then
pts.Add(ent)
Else
plines.Add(ent)
End If
Next
For Each pt As DBPoint In pts
Dim ptPosition As Point2d = New Point2d(pt.Position.X, pt.Position.Y)
Dim Cdist As Double = 1000 '给一个相当大的值作为比较值
Dim Cpt As New Point2d
For Each pline As Polyline In plines
For i As Integer = 0 To pline.NumberOfVertices - 1
Dim dist As Double = ptPosition.GetDistanceTo(pline.GetPoint2dAt(i))
If dist [CommandMethod("tt6")]
public static void test26()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
var resSel =
ed.SelectAll(
new ResultList
{
{ 0, "point,lwpolyline" }
});
List<oint3d> pts = new List<oint3d>();
List<oint3d> nodes = new List<oint3d>();
using (var tr = db.TransactionManager.StartTransaction())
{
foreach (ObjectId id in resSel.Value.GetObjectIds())
{
Entity ent = tr.GetObject(id, OpenMode.ForRead) as Entity;
if (ent is DBPoint)
{
pts.Add(((DBPoint)ent).Position);
}
else
{
Polyline pl = ent as Polyline;
for (int i = 0; i
foreach (Point3d pt in pts)
{
Point3d res = nodes.FindByMinKey(p => p.DistanceTo(pt));
ed.DrawPoint(res.Convert2d(new Plane()), 2, res.DistanceTo(pt), 8);
}
}
}
|
|