Jump to content

Lisp lệnh CHIA trong chủ đề “Nhờ sừa lisp. chia nhỏ pline”

Không biết lệnh JOIN của cad xuất hiện từ phiên bản nào???

(defun c:chia  (/ c_chia_PL ent kc ss)
  (defun c_chia_PL  (ent kc / p oldos oldp findp ss)
    (defun findp (ent) (vlax-curve-getPointAtDist ent kc))
    (setq oldos (getvar "osmode"))
    (setvar "osmode" 0)
    (setq ss (ssadd)
          ss (ssadd ent ss))
    (while (and (setq p (findp ent)) (not (equal p oldp 0.01)))
      (command ".break" ent p p)
      (setq ent  (entlast)
            ss   (ssadd ent ss)
            oldp p))
    (command ".join" ent ss "")
    (setvar "osmode" oldos))
  (if (and (setq ss (ssget '((0 . "LWPOLYLINE"))))
           (setq kc (getdist "\nVAo khoang cach: ")))
    (while (and (setq ent (ssname ss 0)) (ssdel ent ss)) (c_chia_PL ent kc)))
  (princ))

 

Cách dùng

  1. Tải tệp 436729_chia.lsp về máy.
  2. 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ẽ.
  3. Gõ lệnh CHIA để chạy lisp.

Mã nguồn 436729_chia.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/176256-nh%E1%BB%9D-s%E1%BB%ABa-lisp-chia-nh%E1%BB%8F-pline/?tab=comments#comment-436554
(defun c:chia  (/ c_chia_PL ent kc ss)
  (defun c_chia_PL  (ent kc / p oldos oldp findp ss)
    (defun findp (ent) (vlax-curve-getPointAtDist ent kc))
    (setq oldos (getvar "osmode"))
    (setvar "osmode" 0)
    (setq ss (ssadd)
          ss (ssadd ent ss))
    (while (and (setq p (findp ent)) (not (equal p oldp 0.01)))
      (command ".break" ent p p)
      (setq ent  (entlast)
            ss   (ssadd ent ss)
            oldp p))
    (command ".join" ent ss "")
    (setvar "osmode" oldos))
  (if (and (setq ss (ssget '((0 . "LWPOLYLINE"))))
           (setq kc (getdist "\nVAo khoang cach: ")))
    (while (and (setq ent (ssname ss 0)) (ssdel ent ss)) (c_chia_PL ent kc)))
  (princ))

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Nhờ sừa lisp. chia nhỏ pline. Xem đúng bài viết #436729 để đọc hướng dẫn và trao đổi thêm.

Về Thư viện AutoLisp (trang 292)