rocheey 发表于 2022-7-6 17:54:52

.网对不起,我帮不了你,我可能比那里的任何人都环保

SEANT 发表于 2022-7-6 18:00:49

 
下面是VB中的一个示例。净额。我在VB方面没有太多经验。NET-我的大部分。到目前为止,C#一直在使用Net work,因此它可能没有尽可能简洁明了。
 
该项目应包括以下内容:
 
导入Autodesk。AutoCAD。运行时
导入Autodesk。AutoCAD。应用程序服务
导入Autodesk。AutoCAD。数据库服务
导入Autodesk。AutoCAD。编辑输入
导入Autodesk。AutoCAD。几何学
 
Public Sub PlinePtAtDist()
       Dim db As Database = HostApplicationServices.WorkingDatabase
       Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
       db.Pdmode = 66 'just to make the points more visible
       Dim tr As Transaction = db.TransactionManager.StartTransaction()
       Try
         Dim peo As PromptEntityOptions = New PromptEntityOptions(vbCr & "Select a lwpline: ")
         peo.SetRejectMessage(vbCr & "Please select lightweight polyline only! ")
         peo.AddAllowedClass(GetType(Polyline), True)
         Dim per As PromptEntityResult = ed.GetEntity(peo)
         If per.Status <> PromptStatus.OK Then Exit Sub
         Dim pl As Polyline = tr.GetObject(per.ObjectId, OpenMode.ForRead)
         Dim len As Double = pl.Length
         Dim pdo As PromptDoubleOptions = New PromptDoubleOptions(vbCr & "Enter distance from startpoint: ")
         pdo.AllowNegative = False
         pdo.AllowZero = True
         pdo.DefaultValue = len
         pdo.AllowArbitraryInput = False
         Dim pdr As PromptDoubleResult = ed.GetDouble(pdo)
         If pdr.Status <> PromptStatus.OK Or pdr.Value > len Then Exit Sub
         Dim pt As Point3d = pl.GetPointAtParameter(pl.GetParameterAtDistance(pdr.Value)) 'crux of the process
         Dim ptAtDist As DBPoint = New DBPoint(pt)
         Dim btr As BlockTableRecord = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)
         btr.AppendEntity(ptAtDist)
         tr.AddNewlyCreatedDBObject(ptAtDist, True)
         tr.Commit()
       Catch ex As Exception
         tr.Abort()
         ed.WriteMessage("Error during execution! " & ex.Message)
       Finally
         tr.Dispose()
       End Try
   End Sub

SEANT 发表于 2022-7-6 18:05:39

我想我应该通过说我还是一个相对新的(6个月)来限定之前的帖子。Net的任何伪装。我的大部分工作都是在C语言中完成的,但这应该意味着我只走了一小段路。
 
我相信前一篇文章中的代码会起作用,但可能需要额外注意,使其更“防弹”。
 
下面是C版本(我包含了更多的实体)。这可能是一个有趣的比较。
 
顺便提一下,我欢迎对该准则的任何评论和/或批评。
 
 
 
 
 
该项目应包括:
 
使用系统;
使用Autodesk。AutoCAD。运行时间;
使用Autodesk。AutoCAD。应用服务;
使用Autodesk。AutoCAD。数据库服务;
使用Autodesk。AutoCAD。几何学
使用Autodesk。AutoCAD。编辑输入;
 
 
      static public void PlinePtAtDist()
       {
         // Obtain Database and Editor
         Database db = HostApplicationServices.WorkingDatabase;
         Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
         db.Pdmode = 66; // to make point more visible
         PromptEntityOptions entOpts = new PromptEntityOptions("\nSelect a pline or spline entity: ");
         entOpts.SetRejectMessage("\nPlease select LWPoly, 2DPoly, 3DPoly, or spline only! ");
         entOpts.AddAllowedClass(typeof(Polyline), true);
         entOpts.AddAllowedClass(typeof(Polyline2d), true);
         entOpts.AddAllowedClass(typeof(Polyline3d), true);
         entOpts.AddAllowedClass(typeof(Spline), true);

         using (Transaction tr = db.TransactionManager.StartTransaction())
         {
               PromptEntityResult prEntRes = ed.GetEntity(entOpts);
               if (prEntRes.Status != PromptStatus.OK) return; //terminate if no object selected
               Curve crv = (Curve)tr.GetObject(prEntRes.ObjectId, OpenMode.ForRead);
               Double len = crv.GetDistanceAtParameter(crv.EndParam); //total length of curve
               PromptDoubleOptions pdo = new PromptDoubleOptions("\nEnter distance from startpoint: ");
               pdo.AllowNegative = false;
               pdo.AllowZero = true;
               pdo.DefaultValue = len;
               pdo.AllowArbitraryInput = false;
               PromptDoubleResult pdr = ed.GetDouble(pdo);
               if (pdr.Status != PromptStatus.OK || pdr.Value > len) return;//value has been entered and less than total
               Point3d pt = crv.GetPointAtParameter(crv.GetParameterAtDistance(pdr.Value));//crux of routine
               DBPoint ptAtDist = new DBPoint(pt);
               try
               {
                   BlockTableRecord btr = (BlockTableRecord)(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite));
                   btr.AppendEntity(ptAtDist);
                   tr.AddNewlyCreatedDBObject(ptAtDist, true);
                   tr.Commit();
               }
               catch (System.InvalidOperationException ex)
               {
                   tr.Abort();
                   ed.WriteMessage("\nProblem adding point at distance!");
                   ed.WriteMessage(ex.Message);
               }
               finally
               {
                   ed.WriteMessage("\nPoint at Distance command terminated.");
               }
         }

       }

russell84 发表于 2022-7-6 18:10:57

肖恩,
 
谢谢你。
 
我也在看“你好,世界!!!”vb。net示例在网络周围浮动。
 
但是谢谢你,这帮了大忙
 
我只需要了解如何访问这些功能。
 
我仍会看一看,并会尽快发回。
 
干杯
页: 1 [2]
查看完整版本: lisp到vba