修剪穿过所有的实体
请教老师:例如:我用程序画两条线的时候自动修剪所有穿过线...
谢谢狐哥,已通过测试...
public static void Test3()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
var resPt1 = ed.GetPoint("\n选择第一点");
if (resPt1.Status != PromptStatus.OK) return;
var pt1 = resPt1.Value;
var optPt2 = new PromptPointOptions("\n选择第二点");
optPt2.UseBasePoint = true;
optPt2.BasePoint = pt1;
var resPt2 = ed.GetPoint(optPt2);
if (resPt2.Status != PromptStatus.OK) return;
var pt2 = resPt2.Value;
//栏选
var resSel =
ed.SelectFence(
new Point3dCollection { pt1, pt2 },
new ResultList { { 0, "line" } });
if (resSel.Status != PromptStatus.OK) return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
//按两点生成一条直线,并两侧偏移
Line line = new Line(pt1, pt2);
Line line1 = line.GetOffsetCurves(5) as Line;
Line line2 = line.GetOffsetCurves(-5) as Line;
BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
//遍历选择集
SelectionSet ss = resSel.Value;
for (int i = 0; i0)
{
//按交点在直线上的位置排序,并转换为参数集合
var pars =
pts.Cast()
.Select(pnt => iline.GetParameterAtPoint(iline.GetClosestPointTo(pnt, false)))
.OrderBy(par => par);
//按参数集合打断,并排除掉包含栏选点的直线
var lines =
from Line l in iline.GetSplitCurves(new DoubleCollection(pars.ToArray()))
let ls3d = new LineSegment3d(l.StartPoint, l.EndPoint)
where !ls3d.IsOn(pt, new Tolerance(1e-4, 1e-4))
select l;
AddEntity(tr, btr, lines);
iline.Erase();
}
}
AddEntity(tr, btr, line1);
AddEntity(tr, btr, line2);
tr.Commit();
}
}
public static ObjectId AddEntity(Transaction tr, BlockTableRecord btr, Entity ent)
{
ObjectId id = btr.AppendEntity(ent);
tr.AddNewlyCreatedDBObject(ent, true);
return id;
}
public static List AddEntity(Transaction tr, BlockTableRecord btr, IEnumerable ents) where T : Entity
{
List ids = new List();
foreach (T ent in ents)
{
ids.Add(AddEntity(tr, btr, ent));
}
return ids;
}}
好东西,留名留存了!!!!
厉害 Editor.SelectFence Method (Point3dCollection)
谢谢老师,这个"Editor.SelectFence Method (Point3dCollection)"怎么用,目前还不理解,能否再详细一点...
回复
测试的时候调试没有成功,请帮看一下我错在那里...(请看以下图片中的提示)
调试中还是这句where !ls3d.IsOn(pt, new Tolerance(1e-4, 1e-4))通不过...我错在那里 cad2008类库的问题,我一般是用2010/11的类库编译,再在2008里加载的
这句改成:复制代码 谢谢狐哥! 现在已经调试通过了,只是这些代码的意思目前有很多没有理解,后续还要多花点时间慢慢的去理解。。。
页:
[1]
2