Sundar 发表于 2022-7-6 23:08:41

如果你能用autolisp指导我完成同样的任务,那就太好了。。

SEANT 发表于 2022-7-6 23:13:06

我不使用AutoLisp:我更倾向于C语言。净额。
 
在AutoLisp部分发布请求(http://www.cadtutor.net/forum/forumdisplay.php?21-AutoLISP Visual LISP amp DCL)。甚至可能有子例程可用于促进该过程。

Sundar 发表于 2022-7-6 23:15:27

好的,谢谢肖恩。。。

fixo 发表于 2022-7-6 23:19:44

你可以试着从头开始,
比较两个命令的作用

      
       public void IntersectTestIn()
       {
         Database db = HostApplicationServices.WorkingDatabase;
         Document doc = acadApp.DocumentManager.MdiActiveDocument;
         Editor ed = doc.Editor;
         using (Transaction tr = db.TransactionManager.StartTransaction())
         {
               PromptEntityOptions peo = new PromptEntityOptions("\nSelect a Line >>");
               peo.SetRejectMessage("\nYou have to select the Line only >>");
               peo.AddAllowedClass(typeof(Line), false);
               PromptEntityResult res;
               res = ed.GetEntity(peo);
               if (res.Status != PromptStatus.OK)
                   return;
               Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
               if (ent == null)
                   return;
               Line line = (Line)ent as Line;
               if (line == null) return;
               peo = new PromptEntityOptions("\nSelect a Rectangle: ");
               peo.SetRejectMessage("\nYou have to select the Polyline only >>");
               peo.AddAllowedClass(typeof(Polyline), false);
               res = ed.GetEntity("\nSelect a Rectangle: ");
               if (res.Status != PromptStatus.OK)
                   return;
               ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
               if (ent == null)
                   return;
               Polyline pline = (Polyline)ent as Polyline;
               if (line == null) return;
               Point3dCollection pts = new Point3dCollection();
               pline.IntersectWith(line, Intersect.ExtendArgument, pts, 0, 0);
               if (pts.Count == 0) return;
               List<Point3d> points = new List<Point3d>();
               points.Add(line.StartPoint);
               points.Add(line.EndPoint);
               foreach (Point3d p in pts)
                   points.Add(p);
               DBObjectCollection objs = line.GetSplitCurves(pts);
               List<DBObject> lstobj = new List<DBObject>();
               foreach (DBObject dbo in objs)
                   lstobj.Add(dbo);
               points.Sort(delegate(Point3d p1, Point3d p2)
               {
                   return Convert.ToDouble(
                     Convert.ToDouble(line.GetParameterAtPoint(p1))).CompareTo(
                   Convert.ToDouble(line.GetParameterAtPoint(p2)));
               }
      );
               BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
               Line ln0 = lstobj as Line;// middle
               Line ln1 = new Line(points, points);
               Line ln2 = new Line(points, points);
               if (!ln0.IsWriteEnabled)
                   ln0.UpgradeOpen();
               ln0.Dispose();

               if (!ln1.IsWriteEnabled)
                   ln1.UpgradeOpen();
               btr.AppendEntity(ln1);
               tr.AddNewlyCreatedDBObject(ln1, true);
               if (!ln2.IsWriteEnabled)
                   ln2.UpgradeOpen();
   
               btr.AppendEntity(ln2);
               tr.AddNewlyCreatedDBObject(ln2, true);
               if (!line.IsWriteEnabled)
                   line.UpgradeOpen();
               line.Erase();
               line.Dispose();
               ed.Regen();
               tr.Commit();
         }
       }
      
       public void IntersectTest()
       {
         Database db = HostApplicationServices.WorkingDatabase;
         Document doc = acadApp.DocumentManager.MdiActiveDocument;
         Editor ed = doc.Editor;
         using (Transaction tr = db.TransactionManager.StartTransaction())
         {
               PromptEntityOptions peo = new PromptEntityOptions("\nSelect a Line >>");
               peo.SetRejectMessage("\nYou have to select the Line only >>");
               peo.AddAllowedClass(typeof(Line), false);
               PromptEntityResult res;
               res = ed.GetEntity(peo);
               if (res.Status != PromptStatus.OK)
                   return;
               Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
               if (ent == null)
                   return;
               Line line = (Line)ent as Line;
               if (line == null) return;
               peo = new PromptEntityOptions("\nSelect a Rectangle: ");
               peo.SetRejectMessage("\nYou have to select the Polyline only >>");
               peo.AddAllowedClass(typeof(Polyline), false);
               res = ed.GetEntity("\nSelect a Rectangle: ");
               if (res.Status != PromptStatus.OK)
                   return;
               ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
               if (ent == null)
                   return;
               Polyline pline = (Polyline)ent as Polyline;
               if (line == null) return;
               Point3dCollection pts = new Point3dCollection();
               pline.IntersectWith(line, Intersect.ExtendArgument, pts, 0, 0);
               if (pts.Count == 0) return;
               DBObjectCollection lstobj = line.GetSplitCurves(pts);

               BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
               Line ln0 = lstobj as Line;// middle
               Line ln1 = lstobj as Line;

            Line ln2 = lstobj as Line;
               if (!ln0.IsWriteEnabled)
                   ln0.UpgradeOpen();
               btr.AppendEntity(ln0);
               tr.AddNewlyCreatedDBObject(ln0, true);
               if (!ln1.IsWriteEnabled)
                   ln1.UpgradeOpen();
               ln1.Dispose();
            
               if (!ln2.IsWriteEnabled)
                   ln2.UpgradeOpen();
               ln2.Dispose();
            
               if (!line.IsWriteEnabled)
                   line.UpgradeOpen();
               line.Erase();
               line.Dispose();
               ed.Regen();
               tr.Commit();
         }
       }


 
~'J'~

SEANT 发表于 2022-7-6 23:22:58

很好的例子,Fixo。如果他们计划实施一个项目,那么最初的海报将有一个很好的起点。NET解决方案。

fixo 发表于 2022-7-6 23:24:49

很高兴你喜欢
当做

Sundar 发表于 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牛顿
 
请建议我缺少的参考资料。。

fixo 发表于 2022-7-6 23:31:33

此代码未使用互操作
您必须添加对acdbmgd的引用。dll和acmgd。dll
并为两者设置属性“Copy to Local”=False

Sundar 发表于 2022-7-6 23:35:53

我添加了这些引用,并将属性“Copy to Local”设置为False。。但仍然会出现同样的错误。。

SEANT 发表于 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。应用程序服务。应用
页: 1 [2]
查看完整版本: 在矩形内修剪线