jiangfei200809 发表于 2012-7-20 11:04:00

CAD获取一个图形上所有直线的交点


#region 相交判断
      
      public void CrossCAD()
      {
            TypedValue[] pTypeValue = new TypedValue;
            pTypeValue = new TypedValue((int)DxfCode.LayerName, “测试”);
            SelectionFilter pSelectionFilter=new SelectionFilter(pTypeValue);
            PromptSelectionResult selectResult = pDocument.Editor.SelectAll(pSelectionFilter);
            SelectionSet pSelectionSet = selectResult.Value;
            using (Transaction tran = pDatabase.TransactionManager.StartTransaction())
            {
                List crossPoint = new List();//存放相交点
                Autodesk..ApplicationServices.Application.ShowAlertDialog(pSelectionSet.Count.ToString());
                for(int i=0;i= minX && y >= minY && x = minX && y >= minY && x


图层名称我用的是“测试”,大家根据自己需要改下。
通过以上代码可以将一个图层上所有直线相交点用圆的形式标出,希望大家有用

雪山飞狐_lzh 发表于 2012-7-20 12:17:00


纯数学的方法? 不过好像差点代码。。。
试下这段代码      
      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();
                foreach(ObjectId id in res.Value.GetObjectIds())
                {
                  lines.Add((Line)tr.GetObject(id, OpenMode.ForRead));
                }
                List pts = new List();
                for (int m = 0; m < lines.Count; m++)
                {
                  LineSegment3d ls1 = new LineSegment3d(lines.StartPoint, lines.EndPoint);
                  for (int n = m + 1; n < lines.Count; n++)
                  {
                        LineSegment3d ls2 = new LineSegment3d(lines.StartPoint, lines.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();
            }
      }

jiangfei200809 发表于 2012-7-20 14:00:00


缺代码吗 亲?纯数学运算的方法做的 通过构建二元一次方程 然后 判断相交点是否在线上...代码完全可行哈 当然你的代码要简洁点 哈哈

李钊伟2012 发表于 2019-3-26 18:39:00

不是AUTOLISP?看不懂,能否做成一个插件LSP

学知识的小白 发表于 2019-5-16 18:42:00

学习了 感谢楼主
页: [1]
查看完整版本: CAD获取一个图形上所有直线的交点