乐筑天下

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

领队:夹具问题

[复制链接]

9

主题

23

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
59
发表于 2017-8-27 14:16:35 | 显示全部楼层 |阅读模式
由于管理层的一些新指示,我正在尝试创建旧lisp的新.Net版本。下面的代码仅供参考,我也不能因此获得任何荣誉。我想做的基本上是模仿口齿不清的领导人的鬼影和“之字形”。我从基恩的跳汰示例开始,但我还没有做过类似的事情,所以有点不知所措。我知道在C3D中,创建一个样式并继续下去是很容易的,但为此,我的目标是Vanilla AutoCAD
我开始研究是否可能使用MLeader,但发现它并不太好用。如果有人能给我一些指导,我将不胜感激。我并不担心文字、方位或其他任何东西,主要是指引导者,并在用户决定位置时让其预览
  1. ;-------------------------------- C:RL --------------------------------------
  2. ;
  3. ;  Description: Creates a radial line label for a point on a curve
  4. ;
  5. ;  Written By: Robert P. Ehrman
  6. ;
  7. ;  Operation: When you run the program, it will ask you for the "End point
  8. ;             you are describing", this point is the point that you creating
  9. ;             a radial line for. Then it askes you to  "Point on the arc",
  10. ;             this point is automatically snapped to the CENTER OF THE ARC
  11. ;             Finally It will ask you for the location of the label, at this
  12. ;             point you have three options, pick a point, using the ghost
  13. ;             outline supplied as a guide to accurately place the label, or
  14. ;             strike any of the four keys 'I', 'O', {space}, or {enter}.
  15. ;             'I', {space}, and {enter} denote "Inside", 'O' denotes
  16. ;             "Outside". If you pick Inside or Outside, the radial line will
  17. ;             originate at the point you are describing and the label will be
  18. ;             on the appropriate side. If you pick a point, the label will
  19. ;             originate at the point you pick, and the label will appear at
  20. ;             the location shown on the ghost image.
  21. ;            
  22. ;----------------------------------------------------------------------------
  23. (defun C:RL   (/ End Ghost Osmode Cmde Osmode Clayr Cstyle Olderr Ltscale Pt1
  24.            Pt2 Pt3 Cntr Brng1 Ns Ew Degree Minute Second Oldtrk Flag
  25.            Track Temp Angl Angl2 Midtxt)
  26.   (defun End (strng)
  27.     (princ strng)
  28.     (command "LAYER" "S" Clayr "")
  29.     (command "TEXT" "S" Cstyle) (command)
  30.     (setvar "CMDECHO" Cmde)
  31.     (setvar "OSMODE"  Osmode)
  32.     (setq *error* olderr)
  33.     (princ)
  34.   )
  35.   
  36.   (defun Ghost (p1 / Temp Angl2 p2 p3 p4 p5 p7 p8 p9)
  37.     (if (> (distance Cntr P1)
  38.         (distance Cntr Pt1))
  39.       (setq P6 (polar P1 (angle Cntr Pt1) (* Ltscal 1.2)))
  40.     ;else
  41.       (setq P6 (polar P1 (angle Pt1 Cntr) (* Ltscal 1.2))))
  42.     (setq Angl2 (angle P1 P6))
  43.     (if (and ( Angl2 (* 0.5 pi)))
  44.       (setq Side 1.0)
  45.     ;else
  46.       (setq Side -1.0))
  47.     (setq P9 (polar Pt1 Angl2 (+ (abs (- (distance P1 Cntr) (distance Pt1 Cntr)))
  48.                           (* Ltscal 0.1)))
  49.        P2 (polar P1 Angl2 (* Ltscal 0.6))
  50.        P3 (polar P2 (+ Angl2 (* Side 0.5 pi)) (* Ltscal 0.12))
  51.        P4 (polar P3 Angl2 (* Ltscal 0.2))
  52.        P5 (polar P4 (- Angl2 (* Side 0.5 pi)) (* Ltscal 0.12))
  53.        P7 (polar P6 (- Angl2 (* Side 0.5 pi)) (* Ltscal 0.12))
  54.        P10 (polar P1 Angl2 (* Ltscal 0.2))
  55.        P8 (polar P10 (- Angl2 (* Side 0.5 pi)) (* Ltscal 0.12)))
  56.     (grdraw Pt1 P9 -1)
  57.     (grdraw P9 P1 -1)
  58.     (grdraw P1 P6 -1)
  59.     (grdraw P2 P3 -1)
  60.     (grdraw P3 P4 -1)
  61.     (grdraw P4 P5 -1)
  62.     (grdraw P6 P7 -1)
  63.     (grdraw P7 P8 -1)
  64.     (grdraw P8 P10 -1)
  65.     (setq p9 p9)
  66.   )
  67.    
  68.   (setq Cmde     (getvar "CMDECHO")
  69.      Osmode   (getvar "OSMODE")
  70.      Clayr    (getvar "CLAYER")
  71.      Cstyle   (getvar "TEXTSTYLE")
  72.      Olderr   *error*
  73.      *error*  End
  74.      Ltscal   (* 0.86 (getvar "LTSCALE"))
  75.      )
  76.   (setvar "CMDECHO" 0)
  77.   (if (not (tblsearch "LAYER" "V-RADL"))
  78.     (progn
  79.       (princ "\nPlease wait while I create the layer.")
  80.       (if (not (tblsearch "LTYPE" "G-EXIST"))
  81.      (command ".LINETYPE" "load" "G-EXIST" "original" ""))
  82.       (command ".LAYER" "N" "V-RADL"
  83.             "C" "2" "V-RADL"
  84.             "LT" "G-EXIST" "V-RADL" "")))
  85.   (command ".LAYER" "S" "V-RADL" "")
  86.   (setvar "OSMODE" 1025)
  87.   (setq Pt1 (getpoint "\nPick end point on the arc : "))
  88.   (setvar "OSMODE" 0)
  89.   (while Pt1
  90.     (setvar "OSMODE" 1028)
  91.     (setq Cntr (getpoint "\nPick the arc : "))
  92.     (setvar "OSMODE" 0)
  93.     (setq Pt2 (polar Pt1 (angle Pt1 Cntr) (* Ltscal 1.2)))
  94.     (setq Brng1 (angle Pt2 Pt1))
  95.     (setq Brng1 (* 180.0 (/ Brng1 pi)))
  96.     (cond ( (and ( 90 Brng1))
  97.          (setq ns "N"
  98.             ew "E"
  99.             Brng1 (- 90.0 Brng1)))
  100.        ( (and ( 180 Brng1))
  101.          (setq ns "N"
  102.             ew "W"
  103.             Brng1 (- Brng1 90.0)))
  104.        ( (and ( 270 Brng1))
  105.          (setq ns "S"
  106.             ew "W"
  107.             Brng1 (- 270.0 Brng1)))
  108.        ( (and ( 360 Brng1))
  109.          (setq ns "S"
  110.             ew "E"
  111.             Brng1 (- Brng1 270.0))))
  112.     (setq Degree (fix Brng1))
  113.     (setq Brng1 (* 60.0 (- Brng1 (float (fix Brng1)))))
  114.     (setq minute (fix Brng1))
  115.     (setq Brng1 (* 60.0 (- Brng1 (float (fix Brng1)))))
  116.     (setq second (fix Brng1))
  117.     (setq Brng1 (- Brng1 (float (fix Brng1))))
  118.     (if ( 10 Degree)
  119.       (setq Brng1 (strcat ns "0" (itoa Degree) "%%d"))
  120.     ;else
  121.       (setq Brng1 (strcat ns (itoa Degree) "%%d")))
  122.     (if (> 10 Minute)
  123.       (setq Brng1 (strcat Brng1 "0" (itoa Minute) "'"))
  124.     ;else
  125.       (setq Brng1 (strcat Brng1 (itoa Minute) "'")))
  126.     (if (> 10 Second)
  127.       (setq Brng1 (strcat Brng1 "0" (itoa Second) """ ew))
  128.     ;else
  129.       (setq Brng1 (strcat Brng1 (itoa Second) """ ew)))
  130.     (command "TEXT" "S" "S100")(command)
  131.     (setq Oldtrk (cadr (grread 't)))
  132.     (setq Pt5 (ghost Oldtrk))
  133.     (princ "\nLocate label or Inside/Outside [I/O] [I] : \n")
  134.     (setq Flag 1)
  135.     (while Flag
  136.       (setq Track (grread 'T))
  137.       (cond ( (= 2 (car Track))                                 ;Keyboard
  138.            (if (or (= "I" (chr (cadr Track)))                ;Inside
  139.                 (= "i" (chr (cadr Track)))
  140.                 (= 13  (cadr Track))
  141.                 (= 32  (cadr Track)))
  142.           (progn
  143.             (setq Pt5 (ghost Oldtrk))
  144.             (setq Flag NIL)
  145.             (command "DIM1" "LEADER" Pt1 Pt2) (command)
  146.            ) )
  147.            (if (or (= "O" (chr (cadr Track)))                ;Outside
  148.                 (= "o" (chr (cadr Track))))
  149.           (progn
  150.             (setq Pt5 (ghost Oldtrk))
  151.             (setq Flag NIL)
  152.             (setq Pt2 (polar Pt1 (angle Pt2 Pt1) (* Ltscal 1.2)))
  153.             (command "DIM1" "LEADER" Pt1 Pt2) (command)
  154.            ) )
  155.            (if Flag (princ "\rInvalid keystroke.                 "))
  156.          )
  157.          ( (= 3 (car Track))                                 ;Point Selected
  158.            (setq Pt5 (ghost Oldtrk))
  159.            (setq Flag NIL)
  160.            (setq Pt3 (cadr Track))
  161.            (if (> (distance Cntr Pt3)
  162.                (distance Cntr Pt1))
  163.           (setq Pt2 (polar Pt3 (angle Pt2 Pt1) Ltscal))
  164.            ;else
  165.           (setq Pt2 (polar Pt3 (angle Pt1 Pt2) Ltscal)))
  166.            (command "DIM1" "LEADER" Pt1 Pt5 Pt3 Pt2) (command)
  167.            (setq Temp Pt1
  168.               Pt1  Pt3
  169.               Pt3 Temp)
  170.          )
  171.          ( (= 5 (car Track))                                 ;No Point
  172.            (if (not (equal Oldtrk (cadr Track) 0.1))
  173.           (progn
  174.             (setq Pt5 (ghost Oldtrk))
  175.             (setq Oldtrk (cadr Track))
  176.             (setq Pt5 (ghost Oldtrk))
  177.     ) )     ) ) )
  178.     (setq Angl (angle Pt1 Pt2))
  179.     (setq Midtxt (polar Pt1 Angl (* Ltscal 0.7)))
  180.     (if (and ( Angl (* 0.5 pi)))
  181.       (setq Temp Pt2
  182.          Pt2  Pt1
  183.          Pt1  Temp
  184.          Angl (+ Angl pi)))
  185.     (setq Midtxt (polar Midtxt (+ Angl (/ Pi 2.0)) (* Ltscal 0.10)))
  186.     (setq Angl2 (* 180.0 (/ Angl pi)))
  187.     (command "TEXT" "M" Midtxt Angl2 Brng1)
  188.     (setq Midtxt (polar Midtxt (- Angl (/ Pi 2.0)) (* Ltscal 0.20)))
  189.     (command "TEXT" "M" Midtxt Angl2 "(R)")
  190.     (setq Pt1 NIL)
  191.     (initget 0)
  192.     (setvar "OSMODE" 1025)
  193.     (setq Pt1 (getpoint "\nPick point on the arc : "))
  194.     (setvar "OSMODE" 0)
  195.   )
  196.   (End "Function completed.")
  197. )

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2017-8-28 23:55:00 | 显示全部楼层
这是我使用的夹具零件
  1. [/
  2.                 protected override SamplerStatus Sampler(JigPrompts prompts)
  3.                 {
  4.                     JigPromptPointOptions jigOpts = new JigPromptPointOptions();
  5.                     jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates) |
  6.                     UserInputControls.NoNegativeResponseAccepted;
  7.                     
  8.                     jigOpts.Message = jPrompts;
  9.                     jigOpts.BasePoint = P1;
  10.                     jigOpts.UseBasePoint = true;
  11.                     dres = prompts.AcquirePoint(jigOpts);
  12.                     if (dres.Status == PromptStatus.None)
  13.                         return SamplerStatus.Cancel;
  14.                     endPointTemp = dres.Value;
  15.                     if (i == 2)
  16.                     {
  17.                         Pt1 = endPointTemp.TransformBy(ucs.Inverse());
  18.                         Pt2 = EndP.TransformBy(ucs.Inverse());
  19.                         Pt1 = new Point3d(Pt1.X, Pt2.Y,Pt2.Z);
  20.                         
  21.                         endPointTemp = Pt1.TransformBy(ucs);                       
  22.                     }
  23.                     if (endPointTemp != EndP)
  24.                     {
  25.                         EndP = endPointTemp;
  26.                     }
  27.                     else
  28.                     {
  29.                         return SamplerStatus.NoChange;
  30.                     }
  31.                     if (dres.Status == PromptStatus.Cancel)
  32.                         return SamplerStatus.Cancel;
  33.                     else
  34.                         return SamplerStatus.OK;
  35.                 }//End sampler
  36.                 protected override bool Update()
  37.                 {
  38.                     try
  39.                     {
  40.                         Leader leader = Entity as Leader;  
  41.                         leader.SetVertexAt(i, EndP);
  42.                     }
  43.                     catch (System.Exception ex)
  44.                     {  
  45.                         Util.Debug.Print("\nError: " + ex.Message);
  46.                         return false;
  47.                     }
  48.                     return true;
  49.                 }//End Update
  50.                 public Point3d endP()
  51.                 {
  52.                     return EndP;
  53.                 }
  54.                 public PromptPointResult Res()
  55.                 {
  56.                     return dres;
  57.                 }
  58.                 public Entity GetEntity()
  59.                 {
  60.                     return Entity;
  61.                 }
  62.                 public void Addvertex()
  63.                 {
  64.                     i++;
  65.                     P1 = EndP;
  66.                     leader.SetVertexAt(2, P1);
  67.                     leader.AppendVertex(new Point3d(P1.X+0.1,P1.Y,P1.Z));
  68.                 }
  69.             }// End LeaderJig : EntityJig
  70. code]

回复

使用道具 举报

9

主题

23

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
59
发表于 2017-8-29 00:58:04 | 显示全部楼层
谢谢Bryco...我有点晚了,但我会看看这能把我带到哪里。我想我已经有几个问题了,但我会先看看我能去哪里。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-2-4 12:46 , Processed in 0.226070 second(s), 58 queries .

© 2020-2025 乐筑天下

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