在CAD 命令中画多段线的命令为:pline。下面将介绍一种JIG画多段线的方法。

首先,来介绍一下JIG这个东西。

EntityJig(实体动态预览),按照指定步骤模仿特定类型的单个实体对象。首先,定义一个类,该类继承于: Autodesk.AutoCAD.EditorInput.EntityJig。继承该类后,需要重写两个方法。 protected override SamplerStatus Sampler(JigPrompts prompts)和  protected override bool Update()这两个方法。

与正常的Prompt一样需要处理JIG的Prompt。

在Sampler方法中编写如下代码:处理提示消息。并获得用户输入信息

JigPromptPointOptions jigOpts = new JigPromptPointOptions();

jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates |

UserInputControls.NullResponseAccepted |

UserInputControls.NoNegativeResponseAccepted);

在Update方法中更新每一次的拖拽。

完整代码如下:

public class ClsDrawJigLine : Autodesk.AutoCAD.EditorInput.EntityJig

{

#region 成员变量

public static int color = 0;

public static Point3dCollection m_pts;

Point3d m_tempPoint;

Plane m_plane;

#endregion

#region 构造方法

public ClsDrawJigLine(Matrix3d ucs)

: base(new Polyline())

{

m_pts = new Point3dCollection();

Point3d origin = new Point3d(0, 0, 0);

Vector3d normal = new Vector3d(0, 0, 1);

normal = normal.TransformBy(ucs);

m_plane = new Plane(origin, normal);

Polyline pline = Entity as Polyline;

pline.SetDatabaseDefaults();

pline.Normal = normal;

pline.ColorIndex = color;

pline.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);

}

#endregion

/// /// 画线

///

///

///

public Point3dCollection DragLine(int colorIndex)

{

return ClsDrawJigLine.PolyJig(colorIndex);

}

#region 画线方法

/// /// 画线

///

/// 颜色

///

public static Point3dCollection PolyJig(int colorIndex)

{

color = colorIndex;

Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

Matrix3d ucs = ed.CurrentUserCoordinateSystem;

ClsDrawJigLine jig = new ClsDrawJigLine(ucs);

bool bSuccess = true, bComplete = false;

do

{

PromptResult res = ed.Drag(jig);

bSuccess = (res.Status == PromptStatus.OK);

if (bSuccess)

jig.AddLatestVertex();

if (res.Status != PromptStatus.OK)

{

Confirm frm = new Confirm();

frm.ShowDialog();

Confirm.Operate operateType = frm._operrateType;

switch (operateType)

{

case Confirm.Operate.Continue:

bSuccess = true;

bComplete = false;

break;

case Confirm.Operate.Back:

if (m_pts.Count > 0)

{

m_pts.RemoveAt(m_pts.Count - 1);

bSuccess = true;

bComplete = false;

jig.RemoveLastVertex();

}

break;

case Confirm.Operate.Accept:

break;

}

}

} while (bSuccess && !bComplete);

return m_pts;

}

#endregion

#region 用于在完成Drag后,移除最后个虚构的点

/// /// 用于在完成Drag后,移除最后个虚构的点

///

public void RemoveLastVertex()

{

Polyline pline = Entity as Polyline;

if (pline.NumberOfVertices > 1)

{

pline.RemoveVertexAt(m_pts.Count);

}

}

#endregion

#region 在添加一个点时激发事件

/// /// 事件委托

///

/// 事件参数

public delegate void AddHandle(EventArgs e);

public class EventArgs

{

public EventArgs(Point3dCollection currentPoints, int index)

{

this.currentPoints = currentPoints;

this.index = index;

}

/// /// 当前点集合

///

private Point3dCollection currentPoints;

/// /// 当前点集合

///

public Point3dCollection CurrentPoints

{

get { return currentPoints; }

}

/// /// 当前点索引

///

private int index;

/// /// 当前点索引

///

public int Index

{

get { return index; }

}

/// /// 是否取消点绘制

///

private bool isCancel = false;

/// /// 是否取消点绘制

///

public bool IsCancel

{

get { return isCancel; }

set { isCancel = value; }

}

}

/// /// 添加一个点时激发事件

///

public static event AddHandle AddPoint;

#endregion

#region 总是设置polyline为一个虚构的点,在完成Drag后,此点会被移除

/// /// 总是设置polyline为一个虚构的点,在完成Drag后,此点会被移除

///

public void AddLatestVertex()

{

m_pts.Add(m_tempPoint);

Polyline pline = Entity as Polyline;

pline.AddVertexAt(pline.NumberOfVertices, new Point2d(m_tempPoint.X, m_tempPoint.Y), 0, 0, 0);

if (AddPoint != null)

{

EventArgs e = new EventArgs(m_pts, m_pts.Count - 1);

e.IsCancel = false;

AddPoint(e);

if (e.IsCancel)

{

RemoveLastVertex();

}

}

}

#endregion

#region 取样

/// /// 取样

///

///

///

protected override SamplerStatus Sampler(JigPrompts prompts)

{

JigPromptPointOptions jigOpts = new JigPromptPointOptions();

jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates |

UserInputControls.NullResponseAccepted |

UserInputControls.NoNegativeResponseAccepted);

if (m_pts.Count == 0)

{

jigOpts.Message = "\n请输入起点坐标 ";

}

else if (m_pts.Count > 0)

{

jigOpts.BasePoint = m_pts[m_pts.Count - 1];

jigOpts.UseBasePoint = true;

jigOpts.Message = "\n请输入下一个点[或按ESC退出] ";

}

else

return SamplerStatus.Cancel;

PromptPointResult res = prompts.AcquirePoint(jigOpts);

if (m_tempPoint == res.Value)

{

return SamplerStatus.NoChange;

}

else if (res.Status == PromptStatus.OK)

{

m_tempPoint = res.Value;

return SamplerStatus.OK;

}

return SamplerStatus.Cancel;

}

#endregion

#region 更新

/// /// 更新

///

///

protected override bool Update()

{

Polyline pline = Entity as Polyline;

pline.SetPointAt(pline.NumberOfVertices - 1, m_tempPoint.Convert2d(m_plane));

Matrix3d m = Matrix3d.Displacement(new Vector3d(0, 0, 1000));

pline.TransformBy(m);

return true;

}

#endregion

}

其中confirm是一个窗体。用来和用户交互信息,实现交互操作

后台代码为:

/// ///

public partial class Confirm : Form

{

/// ///

// ARXClass _aRXClass = null;

#region 构造方法

/// /// 构造方法

///

public Confirm()

{

//    _aRXClass = new ARXClass();

InitializeComponent();

}

#endregion

#region 操作类型

/// /// 操作类型

///

public enum Operate

{

/// /// 继续

///

Continue = 0,

/// /// 后退

///

Back = 1,

/// /// 确定

///

Accept = 2

}

#endregion

#region 类成员

/// /// 类成员

///

public Operate _operrateType = Operate.Continue;

#endregion

#region 点击继续按钮激发事件

/// /// 点击继续按钮激发事件

///

private void btnContinue_Click(object sender, EventArgs e)

{

this._operrateType = Operate.Continue;

this.Close();

}

#endregion

#region 点击回退按钮激发事件

/// /// 点击回退按钮激发事件

///

private void btnBack_Click(object sender, EventArgs e)

{

this._operrateType = Operate.Back;

this.Close();

}

#endregion

#region 点击确定按钮激发事件

/// /// 点击确定按钮激发事件

///

private void btnAccept_Click(object sender, EventArgs e)

{

// 确定

this._operrateType = Operate.Accept;

// 关闭窗体

this.Close();

}

#endregion

}

以上方法仅供参考。

若各位大侠手里有更好的方法,请顺便贴一下,谢谢。

如有问题:请加qq1419226548或QQmail给我。 若转载,请注明出处。谢谢。

autocad.net 画多段线_auto CAD 二次开发 c#.net 之JIG画多段线(polyline)相关推荐

  1. auto CAD 二次开发 c#.net 之JIG画多段线(polyline)

    在CAD 命令中画多段线的命令为:pline.下面将介绍一种JIG画多段线的方法. 首先,来介绍一下JIG这个东西. EntityJig(实体动态预览),按照指定步骤模仿特定类型的单个实体对象.首先, ...

  2. C# CAD二次开发通过代码模拟 人工 画齿轮的算法思路

    [CommandMethod("FirstLine")]public void FirstLine(){Editor ed = Application.DocumentManage ...

  3. 【CAD二次开发】最完美EntityJig画polyline arc实例

    下面是效果图 2021/10/11更新添加可以捕捉拐点的功能 public static class JigCommand{public static void RunBulgePolyJig(str ...

  4. c# cad二次开发 通过选择txt文件将自动转换成多段线

    c# cad二次开发 通过选择txt文件将自动转换成多段线,txt样式如下 using System; using System.Collections.Generic; using System.T ...

  5. c# CAD二次开发 类库 创建各种图形、直线、圆、多段线、正方形、点等

    c# CAD二次开发 类库 创建各种图形.直线.圆.多段线.正方形.点等 using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD ...

  6. intersect 相交 范围_关于CAD二次开发中(范围线自相交)相交线的问题

    CAD二次开发对于毕业没多久,又是半路出家的我来说,是一个很大的挑战,遇到过很多难以解决的问题,这次在CAD二次开发遇到一个很苦恼的问题:判断 一个由线段组成的闭合区域中,是否存在着相互之间相交的线段 ...

  7. CAD二次开发:用C#在AutoCAD中插入栅格图像

    CAD二次开发:用C#在AutoCAD中插入栅格图像 using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationService ...

  8. lisp CAD二次开发 宗地线自动编号

    lisp CAD二次开发 宗地线自动编号 (defun c:ZZ () (setvar "osmode" 0) (princ "\n选取宗地线-") (setq ...

  9. 使用C#中的AutoCAD .NET API对CAD二次开发,获取动态块可见性值

    使用C#中的AutoCAD .NET API对CAD二次开发,获取动态块可见性值 0.效果 1.获取选择集,得到ObjectId 2.将ObjectId转换为BlockReference对象并获取其D ...

最新文章

  1. 多视图立体匹配论文分享 | Fast-MVSNet (CVPR2020)
  2. 谁是最强的女汉子_JAVA
  3. Python+Opencv颜色和形状检测
  4. 3.eclipse对mysql云数据库编程增删改查
  5. 春运返程高峰来了 大数据看返京热力
  6. 5.2.1.开启驱动开发之路
  7. 谈谈网络游戏中的延迟解决方案
  8. Atlassian JIRA 插件开发之二 安装和创建项目
  9. java数字后面加f_java 数字后面 f 和 l
  10. SDRAM控制器——添加读写FIFO
  11. 计算机声音如何处理器,我电脑运行的声音很大,而且CPU的温度总在70到80之间,怎么办啊?...
  12. 手机app测试方法(一)基本流程
  13. 直角三角形斜边用计算机怎么算,直角三角形斜边怎么算 计算方法有哪些
  14. MacW资讯:苹果MAC电脑便笺字体和颜色怎么修改
  15. 菜狗为了打败菜猫,学了一套如来十三掌
  16. 21.0425开课吧开课前学习
  17. 一款利用PIN管设计的可调衰减器
  18. 刺激越多效果越好?无创神经调控技术(rTMS)缓解疼痛
  19. opencv中findContours 和drawContours画图函数
  20. ORACLE的保留小数或整数函数

热门文章

  1. 思科数据中心网络会议 PPT下载
  2. Android Studio自带的图标以及一些免费的切图素材网页
  3. 美军丑闻再次抽了公知一记耳光
  4. 远程控制预付费集中抄表系统
  5. 高防服务器是什么?怎么选择
  6. 微信浏览器的F12大法!学会随意修改!
  7. 【STM32F407 开发板】实验六 :SysTick 系统滴答实验
  8. mysql数据 odbc_MySQL数据库之mysql odbc 配置详解、解决方案
  9. js判断是否为移动端代码
  10. Qtcreator中使用角蜂鸟相机