乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
楼主: Sundar

[编程交流] 在矩形内修剪线

[复制链接]

6

主题

23

帖子

14

银币

初来乍到

Rank: 1

铜币
34
发表于 2022-7-6 23:08:41 | 显示全部楼层
如果你能用autolisp指导我完成同样的任务,那就太好了。。
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 23:13:06 | 显示全部楼层
我不使用AutoLisp:我更倾向于C语言。净额。
 
在AutoLisp部分发布请求(http://www.cadtutor.net/forum/forumdisplay.php?21-AutoLISP Visual LISP amp DCL)。甚至可能有子例程可用于促进该过程。
回复

使用道具 举报

6

主题

23

帖子

14

银币

初来乍到

Rank: 1

铜币
34
发表于 2022-7-6 23:15:27 | 显示全部楼层
好的,谢谢肖恩。。。
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 23:19:44 | 显示全部楼层
你可以试着从头开始,
比较两个命令的作用
  1.        [CommandMethod("ipLine")]
  2.        public void IntersectTestIn()
  3.        {
  4.            Database db = HostApplicationServices.WorkingDatabase;
  5.            Document doc = acadApp.DocumentManager.MdiActiveDocument;
  6.            Editor ed = doc.Editor;
  7.            using (Transaction tr = db.TransactionManager.StartTransaction())
  8.            {
  9.                PromptEntityOptions peo = new PromptEntityOptions("\nSelect a Line >>");
  10.                peo.SetRejectMessage("\nYou have to select the Line only >>");
  11.                peo.AddAllowedClass(typeof(Line), false);
  12.                PromptEntityResult res;
  13.                res = ed.GetEntity(peo);
  14.                if (res.Status != PromptStatus.OK)
  15.                    return;
  16.                Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
  17.                if (ent == null)
  18.                    return;
  19.                Line line = (Line)ent as Line;
  20.                if (line == null) return;
  21.                peo = new PromptEntityOptions("\nSelect a Rectangle: ");
  22.                peo.SetRejectMessage("\nYou have to select the Polyline only >>");
  23.                peo.AddAllowedClass(typeof(Polyline), false);
  24.                res = ed.GetEntity("\nSelect a Rectangle: ");
  25.                if (res.Status != PromptStatus.OK)
  26.                    return;
  27.                ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
  28.                if (ent == null)
  29.                    return;
  30.                Polyline pline = (Polyline)ent as Polyline;
  31.                if (line == null) return;
  32.                Point3dCollection pts = new Point3dCollection();
  33.                pline.IntersectWith(line, Intersect.ExtendArgument, pts, 0, 0);
  34.                if (pts.Count == 0) return;
  35.                List<Point3d> points = new List<Point3d>();
  36.                points.Add(line.StartPoint);
  37.                points.Add(line.EndPoint);
  38.                foreach (Point3d p in pts)
  39.                    points.Add(p);
  40.                DBObjectCollection objs = line.GetSplitCurves(pts);
  41.                List<DBObject> lstobj = new List<DBObject>();
  42.                foreach (DBObject dbo in objs)
  43.                    lstobj.Add(dbo);
  44.                points.Sort(delegate(Point3d p1, Point3d p2)
  45.                {
  46.                    return Convert.ToDouble(
  47.                        Convert.ToDouble(line.GetParameterAtPoint(p1))).CompareTo(
  48.                    Convert.ToDouble(line.GetParameterAtPoint(p2)));
  49.                }
  50.       );
  51.                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
  52.                Line ln0 = lstobj[1] as Line;// middle
  53.                Line ln1 = new Line(points[0], points[1]);
  54.                Line ln2 = new Line(points[2], points[3]);
  55.                if (!ln0.IsWriteEnabled)
  56.                    ln0.UpgradeOpen();
  57.                ln0.Dispose();
  58.                if (!ln1.IsWriteEnabled)
  59.                    ln1.UpgradeOpen();
  60.                btr.AppendEntity(ln1);
  61.                tr.AddNewlyCreatedDBObject(ln1, true);
  62.                if (!ln2.IsWriteEnabled)
  63.                    ln2.UpgradeOpen();
  64.    
  65.                btr.AppendEntity(ln2);
  66.                tr.AddNewlyCreatedDBObject(ln2, true);
  67.                if (!line.IsWriteEnabled)
  68.                    line.UpgradeOpen();
  69.                line.Erase();
  70.                line.Dispose();
  71.                ed.Regen();
  72.                tr.Commit();
  73.            }
  74.        }
  75.        [CommandMethod("opLine")]
  76.        public void IntersectTest()
  77.        {
  78.            Database db = HostApplicationServices.WorkingDatabase;
  79.            Document doc = acadApp.DocumentManager.MdiActiveDocument;
  80.            Editor ed = doc.Editor;
  81.            using (Transaction tr = db.TransactionManager.StartTransaction())
  82.            {
  83.                PromptEntityOptions peo = new PromptEntityOptions("\nSelect a Line >>");
  84.                peo.SetRejectMessage("\nYou have to select the Line only >>");
  85.                peo.AddAllowedClass(typeof(Line), false);
  86.                PromptEntityResult res;
  87.                res = ed.GetEntity(peo);
  88.                if (res.Status != PromptStatus.OK)
  89.                    return;
  90.                Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
  91.                if (ent == null)
  92.                    return;
  93.                Line line = (Line)ent as Line;
  94.                if (line == null) return;
  95.                peo = new PromptEntityOptions("\nSelect a Rectangle: ");
  96.                peo.SetRejectMessage("\nYou have to select the Polyline only >>");
  97.                peo.AddAllowedClass(typeof(Polyline), false);
  98.                res = ed.GetEntity("\nSelect a Rectangle: ");
  99.                if (res.Status != PromptStatus.OK)
  100.                    return;
  101.                ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
  102.                if (ent == null)
  103.                    return;
  104.                Polyline pline = (Polyline)ent as Polyline;
  105.                if (line == null) return;
  106.                Point3dCollection pts = new Point3dCollection();
  107.                pline.IntersectWith(line, Intersect.ExtendArgument, pts, 0, 0);
  108.                if (pts.Count == 0) return;
  109.                DBObjectCollection lstobj = line.GetSplitCurves(pts);
  110.                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
  111.                Line ln0 = lstobj[1] as Line;// middle
  112.                Line ln1 = lstobj[0] as Line;
  113.   
  114.               Line ln2 = lstobj[2] as Line;
  115.                if (!ln0.IsWriteEnabled)
  116.                    ln0.UpgradeOpen();
  117.                btr.AppendEntity(ln0);
  118.                tr.AddNewlyCreatedDBObject(ln0, true);
  119.                if (!ln1.IsWriteEnabled)
  120.                    ln1.UpgradeOpen();
  121.                ln1.Dispose();
  122.             
  123.                if (!ln2.IsWriteEnabled)
  124.                    ln2.UpgradeOpen();
  125.                ln2.Dispose();
  126.             
  127.                if (!line.IsWriteEnabled)
  128.                    line.UpgradeOpen();
  129.                line.Erase();
  130.                line.Dispose();
  131.                ed.Regen();
  132.                tr.Commit();
  133.            }
  134.        }

 
~'J'~
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 23:22:58 | 显示全部楼层
很好的例子,Fixo。如果他们计划实施一个项目,那么最初的海报将有一个很好的起点。NET解决方案。
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 23:24:49 | 显示全部楼层
很高兴你喜欢
当做
回复

使用道具 举报

6

主题

23

帖子

14

银币

初来乍到

Rank: 1

铜币
34
发表于 2022-7-6 23:29:49 | 显示全部楼层
谢谢你的代码。解决了几乎所有的参考缺失问题。但无法为Documentmanager解决。
此行出错:
 
文档文档=ACADAP。DocumentManager。MdiActiveDocument;
 
错误为:
错误1'Autodesk。AutoCAD。互操作。“AcadApplication”不包含“DocumentManager”的定义,也不包含接受“Autodesk”类型的第一个参数的扩展方法“DocumentManager”。AutoCAD。互操作。可以找到“AcadApplication”(您是否缺少using指令或程序集引用?)D:\Users\Sundar\Visual Studio 2008\NewTrim\NewTrim\Class1。cs 23 27牛顿
 
请建议我缺少的参考资料。。
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 23:31:33 | 显示全部楼层
此代码未使用互操作
您必须添加对acdbmgd的引用。dll和acmgd。dll
并为两者设置属性“Copy to Local”=False
回复

使用道具 举报

6

主题

23

帖子

14

银币

初来乍到

Rank: 1

铜币
34
发表于 2022-7-6 23:35:53 | 显示全部楼层
我添加了这些引用,并将属性“Copy to Local”设置为False。。但仍然会出现同样的错误。。
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 23:37:56 | 显示全部楼层
与本文中的设置类似:
http://www.cadtutor.net/forum/showthread.php?42125-展开-a-text-routine-to-include-MTEXT-DIM&p=284047&viewfull=1#post284047
例程的using statements部分应包括此行:
使用acadApp=Autodesk。AutoCAD。应用程序服务。应用
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 05:58 , Processed in 0.773170 second(s), 70 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表