Failure of long-hole macro

Hi all.

^C^Csetenv;long_hole_width;\setenv;long_hole_length;\setenv;angle;\ucs;z;$M=$(getenv,angle);id;\pline;@$(/,$(getenv, long_hole_length),2),$(/,$(getenv,long_hole_width),2);@-$(getenv,long_hole_length),0;a;@0,-$(getenv,long_hole_width);l;@$(getenv,long_hole_length),0;a;@0,$(getenv,long_hole_width);;ucs;p;^M;

This is a macro used in AutoCAD.
This macro also allows long holes to be drawn in BricsCAD.
However, in BricsCAD, the macro is interrupted when using the Shift+Right click temporary tracking point when indicating coordinates.
Is there a solution?

Thank you.

Comments

  • Interesting how complex people can make things. Don't take that as a criticism, you can even take it as a compliment. I recognize myself, that is all ;-)

    That said, you can make things a lot easier for yourself with CAD-Lisp. I converted the macro, more or less. Whether that solves your problem I don't know, you can test that - just paste the one liner on the command line and enter.

    If you understand the function (polar ...) then it is tempting to replace the whole construction with UCS for (polar ...). See https://developer.bricsys.com/bricscad/help/en_US/V25/DevRef/index.html?page=source/polar.htm for this function and the other functions.

    One-liner:

    (progn (setq lhwidth (getreal "long_hole_width: ")) (setq lhlength (getreal "long_hole_length: ")) (setq centerdist (- lhlength lhwidth)) (setq lhang (getangle "angle: ")) (setq lhpoint (getpoint "point: ")) (setq pt1 (polar (polar lhpoint lhang (/ centerdist 2.0)) (+ (/ pi 2.0) lhang) (/ lhwidth 2.0))) (setq pt2 (polar pt1 (+ lhang pi) centerdist)) (setq pt3 (polar pt2 (+ lhang (* pi 1.5)) lhwidth)) (setq pt4 (polar pt3 lhang centerdist)) (command "._pline" "_non" pt1 "_non" pt2 "_a" "_non" pt3 "_l" "_non" pt4 "_a" "_cl") (princ))

    Or readable Code:

    (progn
      (setq lhwidth (getreal "long_hole_width: ")) ; width, diameter
      (setq lhlength (getreal "long_hole_length: ")) ; total hole length
      (setq centerdist (- lhlength lhwidth)) ; distance between center points
      (setq lhang (getangle "angle: ")) ; hole angle
      (setq lhpoint (getpoint "point: ")) ; insertion point hole
      (setq pt1 ; first point
        (polar ; point - angle - distance ...
          (polar ; get a centre point
            lhpoint ; from this point
            lhang ; with angle
            (/ centerdist 2.0) ; and half dist. between centres
          ) ; now we have a first temp point of pt1...
          (+ (/ pi 2.0) lhang) ; from there the angle plus 90 degrees, pi/2
          (/ lhwidth 2.0) ; and distance half width.
        )
      )
      (setq pt2 (polar pt1 (+ lhang pi) centerdist)) ; next point of pline
      (setq pt3 (polar pt2 (+ lhang (* pi 1.5)) lhwidth)) ; next...
      (setq pt4 (polar pt3 lhang centerdist)) ; last pline point
      (command "._pline" "_non" pt1 "_non" pt2 "_a" "_non" pt3 "_l" "_non" pt4 "_a" "_cl") ; and a command pline
      (princ) ; a clean exit, suppressing last evaluation.
    )



  • As you said, that macro is very complex and I was using it without understanding its contents.
    Also, I was on vacation yesterday and that I wrote it in Lisp.
    And I wrote it using UCS.
    I never thought of using poler, so I will study this as well.
    Thank you very much.

    (defun c:Long_Hole(/ len wid ang pt pb p1 p2 p3 p4)
      (setq len (getreal "\nlength : "))
      (setq wid (getreal "\nwidth : "))
      (setq ang (getreal "\nangle (0) : "))
      (if (= ang nil)
        (setq ang 0)
      )
      (setq pt (getpoint "\npoint : "))
     
      (setq pb (list 0 0))
      (setq p1 (mapcar '- pb (list (/ len 2) (/ wid 2))))
      (setq p2 (list (+ (car pb) (/ len 2)) (- (cadr pb) (/ wid 2))))
      (setq p3 (mapcar '+ pb (list (/ len 2) (/ wid 2))))
      (setq p4 (list (- (car pb) (/ len 2)) (+ (cadr pb) (/ wid 2))))

      (setvar "CmdEcho" 0)
      (command "_UCS" pt "")
      (command "_UCS" "Z" ang)
     
      (command "_POLYLINE" p1 p2 "a" p3 "l" p4 "a" "cl")
     
      (command "_UCS" "W")
      (setvar "CmdEcho" 1)
      (princ)
    )

  • Lisp as Lisp was intended, nice. I would add "_non" statements before points, in order to avoid quirks when osnap is running.