Lisp lệnh LBL trong chủ đề “xin gúp đỡ lisp ve đường tâm”
Forum dạo này bị sao ấy. Thử down thừ đây xem:
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/77029-xin-gup-do-lisp-ve-duong-tam/
; Draw (LW)Polyline between two selected curves (at midpoint of vertices).
(defun c:LBL ( / foo AT:GetSel _pnts _pline _lwpline _dist e1 e2 xx yy)
(vl-load-com)
(defun foo (e)
(and (wcmatch (cdr (assoc 0 (entget (car e)))) "LINE,*POLYLINE,SPLINE")
(not (vlax-curve-isClosed (car e)))))
(defun AT:GetSel (meth msg fnc / ent)
(while
(progn
(setvar 'ERRNO 0)
(setq ent (meth (cond (msg) ("\nSelect object: "))))
(cond
((eq (getvar 'ERRNO) 7) (princ "\nMissed, try again."))
((eq (type (car ent)) 'ENAME)
(if (and fnc (not (fnc ent)))
(princ "\nInvalid object!"))))))
ent)
(defun _pnts (e / p l)
(if e
(cond
((wcmatch (cdr (assoc 0 (entget e))) "ARC,LINE,SPLINE")
(list (vlax-curve-getStartPoint e) (vlax-curve-getEndPoint e)))
((wcmatch (cdr (assoc 0 (entget e))) "*POLYLINE")
(repeat (setq p (1+ (fix (vlax-curve-getEndParam e))))
(setq l (cons (vlax-curve-getPointAtParam e (setq p (1- p))) l)))))))
(defun _pline (lst)
(if
(and
(> (length lst) 1)
(entmakex '((0 . "POLYLINE") (10 0. 0. 0.) (70 . 8)))
(foreach x lst (entmakex (list '(0 . "VERTEX") (cons 10 x) '(70 . 32)))))
(cdr (assoc 330 (entget (entmakex '((0 . "SEQEND"))))))))
(defun _lwpline (lst)
(if (> (length lst) 1)
(entmakex (append
(list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 90 (length lst)) (cons 70 (* (getvar 'plinegen) 128)))
(mapcar (function (lambda (p) (list 10 (car p) (cadr p)))) lst)))))
(defun _dist (a b)
(distance (list (car a) (cadr a)) (list (car b) (cadr b))))
(if
(and
(setq e1 (_pnts (setq xx (car (AT:GetSel entsel "\nSelect first open curve: " foo)))))
(setq e2 (_pnts (setq yy (car (AT:GetSel entsel "\nSelect next open curve: " foo)))))
(not (initget 0 "Lwpolyline Polyline"))
(setq *LBL:Opt* (cond ((getkword (strcat "\nSpecify line to draw: <" (cond (*LBL:Opt*) ((setq *LBL:Opt* "Lwpolyline"))) ">: "))) (*LBL:Opt*))))
((if (eq *LBL:Opt* "Lwpolyline") _lwpline _pline)
(vl-remove nil
(mapcar (function (lambda(a b)
(if (and a b (not (grdraw (trans a 0 1) (trans b 0 1) 1 1)))
(mapcar (function (lambda (a b) (/ (+ a b) 2.))) a b))))
e1
(if (< (_dist (car e1) (car e2)) (_dist (car e1) (last e2))) e2 (reverse e2))))))
(if (and xx yy) (progn (entdel xx) (entdel yy)))
(princ))
Tệp .lsp gốc không còn trên máy chủ. Hãy chép mã nguồn bên dưới (lấy từ bài viết gốc) vào một tệp văn bản, lưu với đuôi .lsp.
Cách dùng
- Chép mã nguồn, lưu thành tệp 291714_lbl.lsp.
- Trong AutoCAD gõ lệnh APPLOAD, chọn tệp vừa tải rồi bấm Load. Cũng có thể kéo thả tệp .lsp vào cửa sổ bản vẽ.
- Gõ lệnh LBL để chạy lisp.
Thảo luận gốc
Lisp được chia sẻ trong chủ đề xin gúp đỡ lisp ve đường tâm. Xem đúng bài viết #291714 để đọc hướng dẫn và trao đổi thêm.