本帖最后由 雪山飞狐_lzh 于 2012-7-20 12:23 编辑
纯数学的方法? 不过好像差点代码。。。
试下这段代码
- [CommandMethod("tx1")]
- public static void CrossCAD()
- {
- var doc = Application.DocumentManager.MdiActiveDocument;
- var db = doc.Database;
- var ed = doc.Editor;
- var sf =
- new SelectionFilter
- (
- new TypedValue[]{ new TypedValue(0, "line")}
- );
- var res = ed.SelectAll(sf);
- if (res.Status != PromptStatus.OK) return;
- using (var tr = doc.TransactionManager.StartTransaction())
- {
- var lines = new List<Line>();
- foreach(ObjectId id in res.Value.GetObjectIds())
- {
- lines.Add((Line)tr.GetObject(id, OpenMode.ForRead));
- }
- List<Point3d> pts = new List<Point3d>();
- for (int m = 0; m < lines.Count; m++)
- {
- LineSegment3d ls1 = new LineSegment3d(lines[m].StartPoint, lines[m].EndPoint);
- for (int n = m + 1; n < lines.Count; n++)
- {
- LineSegment3d ls2 = new LineSegment3d(lines[n].StartPoint, lines[n].EndPoint);
- CurveCurveIntersector3d cc3d = new CurveCurveIntersector3d(ls1, ls2, Vector3d.ZAxis);
- if (cc3d.NumberOfIntersectionPoints == 1)
- {
- pts.Add(cc3d.GetIntersectionPoint(0));
- }
- }
- }
- BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
- BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
- foreach (var pt in pts)
- {
- Circle c = new Circle(pt, Vector3d.ZAxis, 1);
- btr.AppendEntity(c);
- tr.AddNewlyCreatedDBObject(c, true);
- }
- tr.Commit();
- }
- }
|