dbroada 发表于 2022-7-6 22:20:41

三维点和二维多段线

忘了提一下,这是在VB中。网
 
 
我需要在两个选定点之间绘制一条多段线(然后对其进行一些处理)。我最好的前进方式是什么?我正在“学习”的书(你从错误中吸取了教训,不是吗)向我展示了如何操作二维多段线和如何选择三维点。我不能做的是将我的3d点转换成2d点。我错过了什么?

rkmcswain 发表于 2022-7-6 22:32:42

你是说要绘制二维多段线,但要捕捉到三维点并忽略Z高程?

dbroada 发表于 2022-7-6 22:37:32

太快了!
我也刚刚意识到我错过了我在VB中编码的要点。网(对不起)
 
我只需要一条二维(z=0)多段线。

Dim myPline AsNewPolyline
myPline.AddVertexAt(0, NewPoint2d(0, 0), 0, 0, 0) ' myStartPoint
myPline.AddVertexAt(1, NewPoint2d(10, 10), 0, 0, 0) 'myNextPoint

 
我(目前)知道的唯一命令是获取3d点。。。。
 

Dim my3dStartPoint AsPoint3d = DocumentManager.MdiActiveDocument.Editor.GetPoint("start ").Value
Dim my2dStartPoint AsPoint2d = DocumentManager.MdiActiveDocument.Editor.GetPoint("start ").Value

 
第一个有效,第二个无效。我不确定我是否错过了一个简单的转换,或者我是否使用了错误的组件,或者只是错过了一点语法。

BlackBox 发表于 2022-7-6 22:38:48

戴夫,
 
EditorInput的Value属性。PromptResult。。。这是编辑器返回的内容。GetPoint()。。。返回Point3d,这就是为什么转换为Point2d失败的原因。
 
要从点3D获得单个点2D,请考虑使用点3D的X和Y值来创建新的点2D。
 
如果你有列表并且想转换为列表,托尼在这里提供了一些好的建议。

BlackBox 发表于 2022-7-6 22:44:46

这里有一个简单的扩展方法供您使用,它允许您立即从任何Point3d类型中提取Point2d(甚至从EditorInput.PromptResult.Value中),如下所示:
 

namespace Autodesk.AutoCAD.Geometry
{
   public static class Point3dExtensionMethods
   {
       public static Point2d GetPoint2d(this Point3d pt)
       {
         return new Point2d(pt.X, pt.Y);
       }
   }
}

 
... 下面是一个使用它的快速示例:

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.Geometry.Point3dExtensionMethods;

namespace CADTutor.Sample.PointUtilities
{
   class Foo
   {
      
       void FOO()
       {
         Document doc =
                   Application.DocumentManager.MdiActiveDocument;

         Editor ed = doc.Editor;

         PromptPointOptions opts = new PromptPointOptions("");

         opts.Message = "\nSpecify a point: ";

         PromptPointResult ppr = ed.GetPoint(opts);

         if (ppr.Status == PromptStatus.OK)
         {
               Point3d pt = ppr.Value;

               ed.WriteMessage(
                   "\n** = {0}, = {1} ** ",
                   pt.ToString(),
                   pt.GetPoint2d().ToString()
               );
         }
       }
   }
}

BlackBox 发表于 2022-7-6 22:53:31

您可能还会发现这篇ADNDevBlog文章很有用:
 
AutoCAD 2013中的扩展方法

fixo 发表于 2022-7-6 23:02:27

嗨,Dave,请参阅附件中的简单代码,
这是一首老歌,但它对我有用
 
loop_点。txt文件

dbroada 发表于 2022-7-6 23:03:29

谢谢你们,我明天回去工作的时候会好好看看的。
 
再一次,我没有寻找简单的解决方案,只删除一个3d点的z分量!
 
在回家的路上,我突然想到,我还必须想出如何“宣布”普林线应该关闭——看起来fixo的代码中已经包含了这一点。

BlackBox 发表于 2022-7-6 23:13:29

 
..........

dbroada 发表于 2022-7-6 23:15:41

我明白了,你是在评论fixo对Convert2d()的使用。我看这需要一点时间。。。。
页: [1] 2
查看完整版本: 三维点和二维多段线