乐筑天下

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

[求助]如何模仿MLINE用Jig画两条平行线

[复制链接]

52

主题

380

帖子

11

银币

中流砥柱

Rank: 25

铜币
588
发表于 2009-6-22 17:06:00 | 显示全部楼层 |阅读模式
如何模仿MLINE用Jig画两条平行线。
对Jig非常感兴趣,但是实在模不到门路。
希望哪位高手能花点时间给个例子:
1. “指定起点”pt1 命令行显示“平行线间距:100”(默认间距为100)
2.   命令行出现 “指定下一点[平行线间距(S)/放弃(U)]:”
2.1 如果输入S则用getdistance 取得平行线的间距,输完后回到“指定下一点[平行线间距(S)/放弃(U)]:”
2.2  至于放弃(U)这个功能,参看Line命令。
2.3   如果指定了下一点。即返回为点值。即绘制出两条平行的LINE。
3.  如此循环,类似绘制LINE (Mline)
回复

使用道具 举报

52

主题

380

帖子

11

银币

中流砥柱

Rank: 25

铜币
588
发表于 2009-6-22 17:23:00 | 显示全部楼层
类似mline,其对正类型为无(Z).
看KEAN例子,看晕了。
这个应该是动态生成再加上动态输入关键字
如果高手觉得太麻烦。
给个更简单的例子也行:
就是按一楼的那样子,不要生成平行线。
用JIG模仿LINE命令(会不会思路更清晰些)
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2009-6-23 20:59:00 | 显示全部楼层

这几天有点忙:),天天开会,汗
写了个模拟Line的,写的有点乱:)
改写了下,这样可能要清晰一点
实际上Line应该可以不用Jig,这里只是实现一下Jig的流程
双线的Jig加一些计算,改动一下就可以了吧
  1. using System;
  2. using System.Collections.Generic;
  3. using Autodesk.AutoCAD.Runtime;
  4. using Autodesk.AutoCAD.DatabaseServices;
  5. using Autodesk.AutoCAD.ApplicationServices;
  6. using Autodesk.AutoCAD.EditorInput;
  7. using Autodesk.AutoCAD.Geometry;
  8. [assembly: CommandClass(typeof(TlsCad.MyLineJig))]
  9. namespace TlsCad
  10. {
  11.     class MyLineJig : DrawJig
  12.     {
  13.         List m_Points = new List();
  14.         List m_Lines = new List();
  15.         Point3d m_EndPoint;
  16.         LineJigStatus m_Status = LineJigStatus.Add;
  17.         public enum LineJigStatus
  18.         {
  19.             Add,
  20.             Undo,
  21.             Close,
  22.             Finish
  23.         }
  24.         public LineJigStatus JigStatus
  25.         {
  26.             get { return m_Status; }
  27.             set { m_Status = value; }
  28.         }
  29.         public Point3d StartPoint
  30.         {
  31.             get { return m_Points[1]; }
  32.         }
  33.         public Point3d EndPoint
  34.         {
  35.             get { return m_Points[0]; }
  36.         }
  37.         protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
  38.         {
  39.             return true;
  40.         }
  41.         protected override SamplerStatus Sampler(JigPrompts prompts)
  42.         {
  43.             JigPromptPointOptions jigOpts = new JigPromptPointOptions();
  44.             jigOpts.UserInputControls =
  45.                 UserInputControls.Accept3dCoordinates |
  46.                 UserInputControls.NoZeroResponseAccepted |
  47.                 UserInputControls.NoNegativeResponseAccepted |
  48.                 UserInputControls.NullResponseAccepted;
  49.             switch (m_Points.Count)
  50.             {
  51.                 case 0:
  52.                     jigOpts.Message = "\n指定第一点:";
  53.                     break;
  54.                 case 1:
  55.                 case 2:
  56.                     jigOpts.Cursor = CursorType.RubberBand;
  57.                     jigOpts.SetMessageAndKeywords("\n指定下一点或 [放弃(U)]:", "Undo");
  58.                     jigOpts.UseBasePoint = true;
  59.                     jigOpts.BasePoint = m_Points[0];
  60.                     break;
  61.                 default:
  62.                     jigOpts.Cursor = CursorType.RubberBand;
  63.                     jigOpts.SetMessageAndKeywords("\n指定下一点或 [闭合(C)/放弃(U)]:", "Close Undo");
  64.                     jigOpts.UseBasePoint = true;
  65.                     jigOpts.BasePoint = m_Points[0];
  66.                     break;
  67.             }
  68.             PromptPointResult res = prompts.AcquirePoint(jigOpts);
  69.             m_Status = LineJigStatus.Add;
  70.             switch (res.Status)
  71.             {
  72.                 case PromptStatus.Cancel:
  73.                 case PromptStatus.None:
  74.                     m_Status = LineJigStatus.Finish;
  75.                     return SamplerStatus.Cancel;
  76.                 case PromptStatus.Keyword:
  77.                     switch (res.StringResult)
  78.                     {
  79.                         case "Undo":
  80.                             m_Status = LineJigStatus.Undo;
  81.                             break;
  82.                         case "Close":
  83.                             m_EndPoint = m_Points[m_Points.Count - 1];
  84.                             m_Status = LineJigStatus.Close;
  85.                             break;
  86.                     }
  87.                     return SamplerStatus.OK;
  88.                 default:
  89.                     Point3d positionTemp = res.Value;
  90.                     if (positionTemp != m_EndPoint)
  91.                     {
  92.                         m_EndPoint = positionTemp;
  93.                     }
  94.                     else
  95.                     {
  96.                         return SamplerStatus.NoChange;
  97.                     }
  98.                     break;
  99.             }
  100.             return SamplerStatus.OK;
  101.         }
  102.         public int AddPoint()
  103.         {
  104.             m_Points.Insert(0, m_EndPoint);
  105.             return m_Points.Count;
  106.         }
  107.         public void AddLine(Line line)
  108.         {
  109.             m_Lines.Insert(0, line.ObjectId);
  110.         }
  111.         public ObjectId CurrLine
  112.         {
  113.             get { return m_Lines.Count == 0 ? ObjectId.Null : m_Lines[0]; }
  114.         }
  115.         public int RemovePoint()
  116.         {
  117.             m_Points.RemoveAt(0);
  118.             return m_Points.Count;
  119.         }
  120.         public void RemveLine()
  121.         {
  122.             m_Lines.RemoveAt(0);
  123.         }
  124.         [CommandMethod("lj")]
  125.         public static void DoIt()
  126.         {
  127.             MyLineJig ljig = new MyLineJig();
  128.             Document doc = Application.DocumentManager.MdiActiveDocument;
  129.             Database db = doc.Database;
  130.             Editor ed = doc.Editor;
  131.             while (ljig.JigStatus != LineJigStatus.Finish)
  132.             {
  133.                 PromptResult res = ed.Drag(ljig);
  134.                 Line line;
  135.                 switch (ljig.JigStatus)
  136.                 {
  137.                     case LineJigStatus.Add:
  138.                     case LineJigStatus.Close:
  139.                         if (ljig.AddPoint() != 1)
  140.                         {
  141.                             using (Transaction tr = db.TransactionManager.StartTransaction())
  142.                             {
  143.                                 BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
  144.                                 line = new Line(ljig.StartPoint, ljig.EndPoint);
  145.                                 line.SetDatabaseDefaults();
  146.                                 btr.AppendEntity(line);
  147.                                 tr.AddNewlyCreatedDBObject(line, true);
  148.                                 ljig.AddLine(line);
  149.                                 tr.Commit();
  150.                             }
  151.                         }
  152.                         break;
  153.                     case LineJigStatus.Undo:
  154.                         ljig.RemovePoint();
  155.                         if (ljig.CurrLine != ObjectId.Null)
  156.                         {
  157.                             using (Transaction tr = db.TransactionManager.StartTransaction())
  158.                             {
  159.                                 line = (Line)ljig.CurrLine.GetObject(OpenMode.ForWrite);
  160.                                 line.Erase(true);
  161.                                 ljig.RemveLine();
  162.                                 tr.Commit();
  163.                             }
  164.                         }
  165.                         break;
  166.                 }
  167.                 if (ljig.JigStatus == LineJigStatus.Close)
  168.                     ljig.JigStatus = LineJigStatus.Finish;
  169.             }
  170.         }
  171.     }
  172. }
回复

使用道具 举报

52

主题

380

帖子

11

银币

中流砥柱

Rank: 25

铜币
588
发表于 2009-6-24 09:17:00 | 显示全部楼层
太感谢版主了。。。
因为有这么热心的版主。。。
我相信这个版块一定会越办越好。
我先好好学习一下。
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2009-6-27 22:59:00 | 显示全部楼层
试着改写成PolyLine的,:)
没有考虑Ucs的
  1.     class PolyLineJig : DrawJig
  2.     {
  3.         ObjectId m_PolyLine = ObjectId.Null;
  4.         Point3d m_FirstPoint;
  5.         Polyline m_CurrPolyLine;
  6.         Point3d m_StartPoint = Point3d.Origin;
  7.         Vector3d m_StartVector = Vector3d.XAxis;
  8.         Point3d m_EndPoint;
  9.         bool m_IsLine = true;
  10.         int m_Count = -1;
  11.         PolyLineJigStatus m_Status = PolyLineJigStatus.Add;
  12.         public enum PolyLineJigStatus
  13.         {
  14.             Add,
  15.             Keyword,
  16.             Undo,
  17.             Finish,
  18.             Close,
  19.         }
  20.         public PolyLineJig()
  21.         {
  22.             m_CurrPolyLine = new Polyline();
  23.             m_CurrPolyLine.AddVertexAt(0, m_StartPoint.Convert2d(new Plane()), 0, 0, 0);
  24.             m_CurrPolyLine.AddVertexAt(0, m_StartPoint.Convert2d(new Plane()), 0, 0, 0);
  25.         }
  26.         public PolyLineJigStatus JigStatus
  27.         {
  28.             get { return m_Status; }
  29.             set { m_Status = value; }
  30.         }
  31.         public Point3d StartPoint
  32.         {
  33.             get { return m_StartPoint; }
  34.         }
  35.         public Point3d EndPoint
  36.         {
  37.             get { return m_EndPoint; }
  38.         }
  39.         protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
  40.         {
  41.             if (m_Count > -1)
  42.             {
  43.                 double bugle = GetBugle();
  44.                 if (bugle != 0)
  45.                 {
  46.                     m_CurrPolyLine.SetBulgeAt(0, GetBugle());
  47.                     m_CurrPolyLine.SetPointAt(1, m_EndPoint.Convert2d(new Plane()));
  48.                     return draw.Geometry.Draw(m_CurrPolyLine);
  49.                 }
  50.             }
  51.             return true;
  52.         }
  53.         private double GetBugle()
  54.         {
  55.             if (m_IsLine)
  56.             {
  57.                 return 0;
  58.             }
  59.             else
  60.             {
  61.                 Plane plane = new Plane();
  62.                 double ang = (m_EndPoint - m_StartPoint).AngleOnPlane(plane);
  63.                 ang -= m_StartVector.AngleOnPlane(plane);
  64.                 return Math.Tan(ang * 0.5);
  65.             }
  66.         }
  67.         public Polyline Update()
  68.         {
  69.             Polyline pl;
  70.             switch (m_Status)
  71.             {
  72.                 case PolyLineJigStatus.Add:
  73.                 case PolyLineJigStatus.Close:
  74.                     if (m_Count > -1)
  75.                     {
  76.                         pl = (Polyline)m_PolyLine.GetObject(OpenMode.ForWrite);
  77.                         pl.SetBulgeAt(m_Count, GetBugle());
  78.                     }
  79.                     else
  80.                     {
  81.                         pl = new Polyline();
  82.                         m_FirstPoint = m_EndPoint;
  83.                     }
  84.                     m_Count++;
  85.                     pl.AddVertexAt(m_Count, m_EndPoint.Convert2d(new Plane()), GetBugle(), 0, 0);
  86.                     m_StartPoint = m_EndPoint;
  87.                     m_CurrPolyLine.SetPointAt(0, m_StartPoint.Convert2d(new Plane()));
  88.                     try
  89.                     {
  90.                         m_StartVector = pl.GetFirstDerivative(pl.EndParam);
  91.                     }
  92.                     catch
  93.                     {
  94.                         m_StartVector = Vector3d.XAxis;
  95.                     }
  96.                     return pl;
  97.                 case PolyLineJigStatus.Undo:
  98.                     pl = (Polyline)m_PolyLine.GetObject(OpenMode.ForWrite);
  99.                     if (m_Count == 0)
  100.                     {
  101.                         pl.Erase(true);
  102.                         m_PolyLine = ObjectId.Null;
  103.                     }
  104.                     else
  105.                     {
  106.                         pl.RemoveVertexAt(m_Count);
  107.                         m_StartPoint = pl.EndPoint;
  108.                         m_CurrPolyLine.SetPointAt(0, m_StartPoint.Convert2d(new Plane()));
  109.                     }
  110.                     m_Count--;
  111.                     if (m_Count > -1)
  112.                     {
  113.                         m_StartPoint = pl.GetPoint3dAt(m_Count);
  114.                     }
  115.                     try
  116.                     {
  117.                         m_StartVector = pl.GetFirstDerivative(pl.EndParam);
  118.                     }
  119.                     catch
  120.                     {
  121.                         m_StartVector = Vector3d.XAxis;
  122.                     }
  123.                     break;
  124.             }
  125.             return null;
  126.         }
  127.         protected override SamplerStatus Sampler(JigPrompts prompts)
  128.         {
  129.             JigPromptPointOptions jigOpts = new JigPromptPointOptions();
  130.             jigOpts.UserInputControls =
  131.                 UserInputControls.Accept3dCoordinates |
  132.                 UserInputControls.NoZeroResponseAccepted |
  133.                 UserInputControls.NoNegativeResponseAccepted |
  134.                 UserInputControls.NullResponseAccepted;
  135.             switch (m_Count)
  136.             {
  137.                 case -1:
  138.                     jigOpts.Message = "\n指定第一点:";
  139.                     break;
  140.                 case 0:
  141.                 case 1:
  142.                     jigOpts.Cursor = CursorType.RubberBand;
  143.                     jigOpts.Message = "\n指定下一个点:";
  144.                     if (m_IsLine)
  145.                     {
  146.                         jigOpts.Keywords.Add("Arc", "Arc", "圆弧(A)");
  147.                     }
  148.                     else
  149.                     {
  150.                         jigOpts.Keywords.Add("Line", "Line", "直线(L)");
  151.                     }
  152.                     jigOpts.Keywords.Add("Undo", "Undo", "放弃(U)");
  153.                     jigOpts.UseBasePoint = true;
  154.                     jigOpts.BasePoint = m_StartPoint;
  155.                     break;
  156.                 default:
  157.                     jigOpts.Cursor = CursorType.RubberBand;
  158.                     jigOpts.Message = "\n指定下一个点:";
  159.                     if (m_IsLine)
  160.                     {
  161.                         jigOpts.Keywords.Add("Arc", "Arc", "圆弧(A)");
  162.                     }
  163.                     else
  164.                     {
  165.                         jigOpts.Keywords.Add("Line", "Line", "直线(L)");
  166.                     }
  167.                     jigOpts.Keywords.Add("Close", "Close", "闭合(C)");
  168.                     jigOpts.Keywords.Add("Undo", "Undo", "放弃(U)");
  169.                     jigOpts.UseBasePoint = true;
  170.                     jigOpts.BasePoint = m_StartPoint;
  171.                     break;
  172.             }
  173.             PromptPointResult res = prompts.AcquirePoint(jigOpts);
  174.             m_Status = PolyLineJigStatus.Add;
  175.             switch (res.Status)
  176.             {
  177.                 case PromptStatus.Cancel:
  178.                 case PromptStatus.None:
  179.                     m_Status = PolyLineJigStatus.Finish;
  180.                     return SamplerStatus.Cancel;
  181.                 case PromptStatus.Keyword:
  182.                     switch (res.StringResult)
  183.                     {
  184.                         case "Arc":
  185.                         case "Line":
  186.                             m_IsLine = !m_IsLine;
  187.                             m_Status = PolyLineJigStatus.Keyword;
  188.                             return SamplerStatus.OK;
  189.                         case "Add":
  190.                             m_Status = PolyLineJigStatus.Add;
  191.                             return SamplerStatus.OK;
  192.                         case "Undo":
  193.                             m_Status = PolyLineJigStatus.Undo;
  194.                             return SamplerStatus.OK;
  195.                         case "Close":
  196.                             m_EndPoint = m_FirstPoint;
  197.                             m_Status = PolyLineJigStatus.Close;
  198.                             return SamplerStatus.Cancel;
  199.                     }
  200.                     break;
  201.                 default:
  202.                     Point3d positionTemp = res.Value;
  203.                     if (positionTemp != m_EndPoint)
  204.                     {
  205.                         m_EndPoint = positionTemp;
  206.                     }
  207.                     else
  208.                     {
  209.                         return SamplerStatus.NoChange;
  210.                     }
  211.                     break;
  212.             }
  213.             return SamplerStatus.OK;
  214.         }        [CommandMethod("plj")]
  215.         public static void DoIt()
  216.         {
  217.             PolyLineJig ljig = new PolyLineJig();
  218.             Document doc = Application.DocumentManager.MdiActiveDocument;
  219.             Database db = doc.Database;
  220.             Editor ed = doc.Editor;
  221.             while (ljig.JigStatus != PolyLineJigStatus.Finish)
  222.             {
  223.                 ed.Drag(ljig);
  224.                 using (Transaction tr = db.TransactionManager.StartTransaction())
  225.                 {
  226.                     Polyline pl = ljig.Update();
  227.                     if (ljig.m_PolyLine == ObjectId.Null && pl != null)
  228.                     {
  229.                         BlockTableRecord btr = db.CurrentSpaceId.GetObject(OpenMode.ForWrite) as BlockTableRecord;
  230.                         ljig.m_PolyLine = btr.AppendEntity(pl);
  231.                         tr.AddNewlyCreatedDBObject(pl, true);
  232.                     }
  233.                     tr.Commit();
  234.                 }
  235.                 if (ljig.JigStatus == PolyLineJigStatus.Close)
  236.                     ljig.JigStatus = PolyLineJigStatus.Finish;
  237.             }
  238.         }
  239.     }
回复

使用道具 举报

10

主题

36

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
76
发表于 2009-8-4 09:28:00 | 显示全部楼层
怎么看不到
回复

使用道具 举报

1

主题

5

帖子

1

银币

初来乍到

Rank: 1

铜币
9
发表于 2011-3-21 14:05:00 | 显示全部楼层
学习了......
回复

使用道具 举报

40

主题

133

帖子

25

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
277
发表于 2012-2-22 17:02:00 | 显示全部楼层

学习了。就是用plj时,每次只是显示一条线,前一步的线要是也能显示出来,就和本身的pl命令一样了。那就太棒了。
lj点击输入下一点后,线怎么不画出来?
回复

使用道具 举报

68

主题

645

帖子

23

银币

中流砥柱

Rank: 25

铜币
910
发表于 2012-2-26 21:38:00 | 显示全部楼层
第一次来这里,还不知道程序怎么用,保存的后缀是什么?命令名是什么?还望多多指教
回复

使用道具 举报

0

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
1
发表于 2012-2-27 18:47:00 | 显示全部楼层
2.3   如果指定了下一点。即返回为点值。即绘制出两条平行的LINE。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-15 21:18 , Processed in 0.392555 second(s), 72 queries .

© 2020-2025 乐筑天下

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