rugaroo 发表于 2017-8-27 14:16:35

领队:夹具问题

由于管理层的一些新指示,我正在尝试创建旧lisp的新.Net版本。下面的代码仅供参考,我也不能因此获得任何荣誉。我想做的基本上是模仿口齿不清的领导人的鬼影和“之字形”。我从基恩的跳汰示例开始,但我还没有做过类似的事情,所以有点不知所措。我知道在C3D中,创建一个样式并继续下去是很容易的,但为此,我的目标是Vanilla AutoCAD
我开始研究是否可能使用MLeader,但发现它并不太好用。如果有人能给我一些指导,我将不胜感激。我并不担心文字、方位或其他任何东西,主要是指引导者,并在用户决定位置时让其预览
;-------------------------------- C:RL --------------------------------------
;
;Description: Creates a radial line label for a point on a curve
;
;Written By: Robert P. Ehrman
;
;Operation: When you run the program, it will ask you for the "End point
;             you are describing", this point is the point that you creating
;             a radial line for. Then it askes you to"Point on the arc",
;             this point is automatically snapped to the CENTER OF THE ARC
;             Finally It will ask you for the location of the label, at this
;             point you have three options, pick a point, using the ghost
;             outline supplied as a guide to accurately place the label, or
;             strike any of the four keys 'I', 'O', {space}, or {enter}.
;             'I', {space}, and {enter} denote "Inside", 'O' denotes
;             "Outside". If you pick Inside or Outside, the radial line will
;             originate at the point you are describing and the label will be
;             on the appropriate side. If you pick a point, the label will
;             originate at the point you pick, and the label will appear at
;             the location shown on the ghost image.
;            
;----------------------------------------------------------------------------
(defun C:RL   (/ End Ghost Osmode Cmde Osmode Clayr Cstyle Olderr Ltscale Pt1
         Pt2 Pt3 Cntr Brng1 Ns Ew Degree Minute Second Oldtrk Flag
         Track Temp Angl Angl2 Midtxt)
(defun End (strng)
    (princ strng)
    (command "LAYER" "S" Clayr "")
    (command "TEXT" "S" Cstyle) (command)
    (setvar "CMDECHO" Cmde)
    (setvar "OSMODE"Osmode)
    (setq *error* olderr)
    (princ)
)

(defun Ghost (p1 / Temp Angl2 p2 p3 p4 p5 p7 p8 p9)
    (if (> (distance Cntr P1)
      (distance Cntr Pt1))
      (setq P6 (polar P1 (angle Cntr Pt1) (* Ltscal 1.2)))
    ;else
      (setq P6 (polar P1 (angle Pt1 Cntr) (* Ltscal 1.2))))
    (setq Angl2 (angle P1 P6))
    (if (and ( Angl2 (* 0.5 pi)))
      (setq Side 1.0)
    ;else
      (setq Side -1.0))
    (setq P9 (polar Pt1 Angl2 (+ (abs (- (distance P1 Cntr) (distance Pt1 Cntr)))
                        (* Ltscal 0.1)))
       P2 (polar P1 Angl2 (* Ltscal 0.6))
       P3 (polar P2 (+ Angl2 (* Side 0.5 pi)) (* Ltscal 0.12))
       P4 (polar P3 Angl2 (* Ltscal 0.2))
       P5 (polar P4 (- Angl2 (* Side 0.5 pi)) (* Ltscal 0.12))
       P7 (polar P6 (- Angl2 (* Side 0.5 pi)) (* Ltscal 0.12))
       P10 (polar P1 Angl2 (* Ltscal 0.2))
       P8 (polar P10 (- Angl2 (* Side 0.5 pi)) (* Ltscal 0.12)))
    (grdraw Pt1 P9 -1)
    (grdraw P9 P1 -1)
    (grdraw P1 P6 -1)
    (grdraw P2 P3 -1)
    (grdraw P3 P4 -1)
    (grdraw P4 P5 -1)
    (grdraw P6 P7 -1)
    (grdraw P7 P8 -1)
    (grdraw P8 P10 -1)
    (setq p9 p9)
)
   
(setq Cmde   (getvar "CMDECHO")
   Osmode   (getvar "OSMODE")
   Clayr    (getvar "CLAYER")
   Cstyle   (getvar "TEXTSTYLE")
   Olderr   *error*
   *error*End
   Ltscal   (* 0.86 (getvar "LTSCALE"))
   )
(setvar "CMDECHO" 0)
(if (not (tblsearch "LAYER" "V-RADL"))
    (progn
      (princ "\nPlease wait while I create the layer.")
      (if (not (tblsearch "LTYPE" "G-EXIST"))
   (command ".LINETYPE" "load" "G-EXIST" "original" ""))
      (command ".LAYER" "N" "V-RADL"
            "C" "2" "V-RADL"
            "LT" "G-EXIST" "V-RADL" "")))
(command ".LAYER" "S" "V-RADL" "")
(setvar "OSMODE" 1025)
(setq Pt1 (getpoint "\nPick end point on the arc : "))
(setvar "OSMODE" 0)
(while Pt1
    (setvar "OSMODE" 1028)
    (setq Cntr (getpoint "\nPick the arc : "))
    (setvar "OSMODE" 0)
    (setq Pt2 (polar Pt1 (angle Pt1 Cntr) (* Ltscal 1.2)))
    (setq Brng1 (angle Pt2 Pt1))
    (setq Brng1 (* 180.0 (/ Brng1 pi)))
    (cond ( (and ( 90 Brng1))
         (setq ns "N"
            ew "E"
            Brng1 (- 90.0 Brng1)))
       ( (and ( 180 Brng1))
         (setq ns "N"
            ew "W"
            Brng1 (- Brng1 90.0)))
       ( (and ( 270 Brng1))
         (setq ns "S"
            ew "W"
            Brng1 (- 270.0 Brng1)))
       ( (and ( 360 Brng1))
         (setq ns "S"
            ew "E"
            Brng1 (- Brng1 270.0))))
    (setq Degree (fix Brng1))
    (setq Brng1 (* 60.0 (- Brng1 (float (fix Brng1)))))
    (setq minute (fix Brng1))
    (setq Brng1 (* 60.0 (- Brng1 (float (fix Brng1)))))
    (setq second (fix Brng1))
    (setq Brng1 (- Brng1 (float (fix Brng1))))
    (if ( 10 Degree)
      (setq Brng1 (strcat ns "0" (itoa Degree) "%%d"))
    ;else
      (setq Brng1 (strcat ns (itoa Degree) "%%d")))
    (if (> 10 Minute)
      (setq Brng1 (strcat Brng1 "0" (itoa Minute) "'"))
    ;else
      (setq Brng1 (strcat Brng1 (itoa Minute) "'")))
    (if (> 10 Second)
      (setq Brng1 (strcat Brng1 "0" (itoa Second) "\"" ew))
    ;else
      (setq Brng1 (strcat Brng1 (itoa Second) "\"" ew)))
    (command "TEXT" "S" "S100")(command)
    (setq Oldtrk (cadr (grread 't)))
    (setq Pt5 (ghost Oldtrk))
    (princ "\nLocate label or Inside/Outside : \n")
    (setq Flag 1)
    (while Flag
      (setq Track (grread 'T))
      (cond ( (= 2 (car Track))                                 ;Keyboard
         (if (or (= "I" (chr (cadr Track)))                ;Inside
                (= "i" (chr (cadr Track)))
                (= 13(cadr Track))
                (= 32(cadr Track)))
          (progn
            (setq Pt5 (ghost Oldtrk))
            (setq Flag NIL)
            (command "DIM1" "LEADER" Pt1 Pt2) (command)
         ) )
         (if (or (= "O" (chr (cadr Track)))                ;Outside
                (= "o" (chr (cadr Track))))
          (progn
            (setq Pt5 (ghost Oldtrk))
            (setq Flag NIL)
            (setq Pt2 (polar Pt1 (angle Pt2 Pt1) (* Ltscal 1.2)))
            (command "DIM1" "LEADER" Pt1 Pt2) (command)
         ) )
         (if Flag (princ "\rInvalid keystroke.               "))
         )
         ( (= 3 (car Track))                                 ;Point Selected
         (setq Pt5 (ghost Oldtrk))
         (setq Flag NIL)
         (setq Pt3 (cadr Track))
         (if (> (distance Cntr Pt3)
               (distance Cntr Pt1))
          (setq Pt2 (polar Pt3 (angle Pt2 Pt1) Ltscal))
         ;else
          (setq Pt2 (polar Pt3 (angle Pt1 Pt2) Ltscal)))
         (command "DIM1" "LEADER" Pt1 Pt5 Pt3 Pt2) (command)
         (setq Temp Pt1
            Pt1Pt3
            Pt3 Temp)
         )
         ( (= 5 (car Track))                                 ;No Point
         (if (not (equal Oldtrk (cadr Track) 0.1))
          (progn
            (setq Pt5 (ghost Oldtrk))
            (setq Oldtrk (cadr Track))
            (setq Pt5 (ghost Oldtrk))
    ) )   ) ) )
    (setq Angl (angle Pt1 Pt2))
    (setq Midtxt (polar Pt1 Angl (* Ltscal 0.7)))
    (if (and ( Angl (* 0.5 pi)))
      (setq Temp Pt2
         Pt2Pt1
         Pt1Temp
         Angl (+ Angl pi)))
    (setq Midtxt (polar Midtxt (+ Angl (/ Pi 2.0)) (* Ltscal 0.10)))
    (setq Angl2 (* 180.0 (/ Angl pi)))
    (command "TEXT" "M" Midtxt Angl2 Brng1)
    (setq Midtxt (polar Midtxt (- Angl (/ Pi 2.0)) (* Ltscal 0.20)))
    (command "TEXT" "M" Midtxt Angl2 "(R)")
    (setq Pt1 NIL)
    (initget 0)
    (setvar "OSMODE" 1025)
    (setq Pt1 (getpoint "\nPick point on the arc : "))
    (setvar "OSMODE" 0)
)
(End "Function completed.")
)

**** Hidden Message *****

Bryco 发表于 2017-8-28 23:55:00

这是我使用的夹具零件
[/
                protected override SamplerStatus Sampler(JigPrompts prompts)
                {
                  JigPromptPointOptions jigOpts = new JigPromptPointOptions();
                  jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates) |
                  UserInputControls.NoNegativeResponseAccepted;
                  
                  jigOpts.Message = jPrompts;
                  jigOpts.BasePoint = P1;
                  jigOpts.UseBasePoint = true;
                  dres = prompts.AcquirePoint(jigOpts);
                  if (dres.Status == PromptStatus.None)
                        return SamplerStatus.Cancel;
                  endPointTemp = dres.Value;
                  if (i == 2)
                  {
                        Pt1 = endPointTemp.TransformBy(ucs.Inverse());
                        Pt2 = EndP.TransformBy(ucs.Inverse());
                        Pt1 = new Point3d(Pt1.X, Pt2.Y,Pt2.Z);
                        
                        endPointTemp = Pt1.TransformBy(ucs);                     
                  }
                  if (endPointTemp != EndP)
                  {
                        EndP = endPointTemp;
                  }
                  else
                  {
                        return SamplerStatus.NoChange;
                  }
                  if (dres.Status == PromptStatus.Cancel)
                        return SamplerStatus.Cancel;
                  else
                        return SamplerStatus.OK;
                }//End sampler
                protected override bool Update()
                {
                  try
                  {
                        Leader leader = Entity as Leader;
                        leader.SetVertexAt(i, EndP);
                  }
                  catch (System.Exception ex)
                  {
                        Util.Debug.Print("\nError: " + ex.Message);
                        return false;
                  }
                  return true;
                }//End Update
                public Point3d endP()
                {
                  return EndP;
                }
                public PromptPointResult Res()
                {
                  return dres;
                }
                public Entity GetEntity()
                {
                  return Entity;
                }
                public void Addvertex()
                {
                  i++;
                  P1 = EndP;
                  leader.SetVertexAt(2, P1);
                  leader.AppendVertex(new Point3d(P1.X+0.1,P1.Y,P1.Z));
                }
            }// End LeaderJig : EntityJig
code]

rugaroo 发表于 2017-8-29 00:58:04

谢谢Bryco...我有点晚了,但我会看看这能把我带到哪里。我想我已经有几个问题了,但我会先看看我能去哪里。
页: [1]
查看完整版本: 领队:夹具问题