Help with little lisp

Help with little lisp

DC-MWA
Collaborator Collaborator
589 Views
6 Replies
Message 1 of 7

Help with little lisp

DC-MWA
Collaborator
Collaborator

Hello,

I'm need of assistance on this little lisp. It uses a block called dvent.dwg. I'm hoping to have the program draw the end cap rather than insert the block and wait for the rotation angle. I'm hoping there is a way to get the angle of the last segment of polyline and draw the end cap based on that angle.

DCMWA_0-1727209336444.png

 

Thank you in advance for any assistance.

-dc

0 Likes
Accepted solutions (1)
590 Views
6 Replies
Replies (6)
Message 2 of 7

CADaSchtroumpf
Advisor
Advisor

I can propose this?

(defun c:dvent ( / ogplwidth firstpt obj dxf_obj obj pt1_start pt1_end par pt2_start pt2_end name_blk dxf_210)
  (defun z_dir (p1 p2 / )
    (trans
      '(0.0 1.0 0.0)
      (mapcar
        '(lambda (k)
          (/ k
            (sqrt
              (apply '+
                (mapcar
                  '(lambda (x) (* x x))
                  (mapcar '- p2 p1)
                )
              )
            )
          )
        )
        (mapcar '- p2 p1)
      )
      0
    )
  )
  (setq ogplwidth (getvar "plinewid"))
  (setvar "plinewid" 1.5)
  (setq firstpt (getpoint "\nSelect point at dryer start point"))
  (command "_.pline" firstpt)
  (while (= 1 (logand 1 (getvar 'cmdactive)))
    (command pause)
    (prompt "\nPick next point along path <Enter> to finish:")
  )
  (setvar "plinewid" ogplwidth)
  (setq obj (entlast))
  (if (not (tblsearch "BLOCK" "dvent"))
    (progn
      (entmake
        '(
          (0 . "BLOCK")
          (100 . "AcDbEntity")
          (67 . 0)
          (8 . "0")
          (100 . "AcDbBlockBegin")
          (70 . 0)
          (10 0.0 0.0 0.0)
          (2 . "dvent")
          (1 . "")
        )
      )
      (entmake
        '(
          (0 . "LWPOLYLINE")
          (100 . "AcDbEntity")
          (67 . 0)
          (410 . "Model")
          (8 . "0")
          (100 . "AcDbPolyline")
          (90 . 4)
          (70 . 0)
          (43 . 0.0)
          (38 . 0.0)
          (39 . 0.0)
          (10 -1.5 -2.0)
          (40 . 0.0)
          (41 . 0.0)
          (42 . 0.0)
          (91 . 0)
          (10 1.5 -2.0)
          (40 . 0.0)
          (41 . 0.0)
          (42 . 0.0)
          (91 . 0)
          (10 1.5 2.0)
          (40 . 0.0)
          (41 . 0.0)
          (42 . 0.0)
          (91 . 0)
          (10 -1.5 2.0)
          (40 . 0.0)
          (41 . 0.0)
          (42 . 0.0)
          (91 . 0)
          (210 0.0 0.0 1.0)
        )
      )
      (entmake '((0 . "ENDBLK") (8 . "0") (62 . 0) (6 . "ByBlock") (370 . -2)))
    )
  )
  (cond
    ((and
      (eq (cdr (assoc 0 (setq dxf_obj (entget obj)))) "LWPOLYLINE")
      (zerop (boole 1 128 (cdr (assoc 70 dxf_obj))))
    )
      (vl-load-com)
      (setq
        pt1_start (vlax-curve-getStartPoint obj)
        pt1_end (vlax-curve-getEndPoint obj)
        par (vlax-curve-getParamAtPoint obj pt1_end)
      )
      (cond
        ((not (zerop par))
          (setq
            pt2_start (vlax-curve-getPointAtParam obj 1)
            pt2_end (vlax-curve-getPointAtParam obj (1- par))
          )
          (foreach n (list (list pt1_start pt2_start) (list pt1_end pt2_end))
            (setq dxf_210 (z_dir (car n) (cadr n)))
            (entmake
              (list
                (cons 0 "INSERT")
                (cons 100 "AcDbEntity")
                (assoc 67 dxf_obj)
                (assoc 410 dxf_obj)
                (cons 8 (getvar "CLAYER"))
                (cons 100 "AcDbBlockReference")
                (cons 2 "dvent")
                (cons 10 (trans (car n) 0 dxf_210))
                (cons 50 (+ pi (angle (trans (car n) 0 dxf_210) (trans (cadr n) 0 dxf_210))))
                (cons 210 dxf_210)
              )
            )
          )
        )
      )
    )
    (T
      (princ "\nIsn't 2Dpolyline avalaible for this function!")
    )
  )
  (prin1)
)
Message 3 of 7

DC-MWA
Collaborator
Collaborator

This is awesome. I only need the cap on the end of the final pickpoint.

0 Likes
Message 4 of 7

CADaSchtroumpf
Advisor
Advisor
Accepted solution

For this change at line 104

(foreach n (list (list pt1_start pt2_start) (list pt1_end pt2_end))

to

(foreach n (list (list pt1_end pt2_end))
0 Likes
Message 5 of 7

DC-MWA
Collaborator
Collaborator
Thank you very much!!!!
0 Likes
Message 6 of 7

komondormrex
Mentor
Mentor

hey there,

how is the cap geometry related to the pline width? i mean, if a pline has a width other than 1.5? does the pline drawn always straight-segmented?

0 Likes
Message 7 of 7

DC-MWA
Collaborator
Collaborator
For the use I intended for this little program, it defaults to 1.5 inches always.
0 Likes