Jump to content

(GÓC NHỜ VẢ) XIN LISP TÍNH ĐỘ DỐC ĐOẠN THẲNG VÀ XÓA NHỮNG ĐOẠN THẲNG CÓ ĐỘ DỐC THEO ĐIỀU KIỆN

@hatrongquan88của bạn đây

(defun c:nht (/ EN L LAY LSP P X Y)
  (princ "\nChon duong pline")
  (while (setq en (ssget '((0 . "*POLYLINE"))))
    (foreach en	(vl-remove-if 'listp (mapcar 'cadr (ssnamex en)))
      (setq lay (cdr (assoc 8 (entget en))))
      (setq lsp
	     (mapcar
	       'cdr
	       (vl-remove-if-not '(lambda (x) (= 10 (car x))) (entget en))
	     ) ;_ end of mapcar
      ) ;_ end of setq
      (mapcar
	'(lambda (x y)
	   (setq l (mapcar '- x y))
	   (if (>= (abs (/ (cadr l) (car l))) 0.3) ;DO DOC LON HON 30%
	     (entmakex
	       (append
		 (list (cons 0 "LWPOLYLINE")
		       (cons 100 "AcDbEntity")
		       (cons 100 "AcDbPolyline")
		       (cons 90 2)
		       (cons 8 LAY)
		 ) ;_ end of list
		 (mapcar (function (lambda (p) (cons 10 p))) (LIST X Y))
	       ) ;_ end of append
	     ) ;_ end of entmakex
	   ) ;_ end of if
	 ) ;_ end of lambda
	lsp
	(cdr lsp)
      ) ;_ end of mapcar
      (entdel en)
    ) ;_ end of foreach
  ) ;_ end of while
  (princ)
) ;_ end of defun

 

Cách dùng

  1. Tải tệp 439158_nht.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 NHT để chạy lisp.

Mã nguồn 439158_nht.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/177173-%C4%91%C3%A3-xong-xin-lisp-t%C3%ADnh-%C4%91%E1%BB%99-d%E1%BB%91c-%C4%91o%E1%BA%A1n-th%E1%BA%B3ng-v%C3%A0-x%C3%B3a-nh%E1%BB%AFng-%C4%91o%E1%BA%A1n-th%E1%BA%B3ng-c%C3%B3-%C4%91%E1%BB%99-d%E1%BB%91c-theo-%C4%91i%E1%BB%81u-ki%E1%BB%87n/
(defun c:nht (/ EN L LAY LSP P X Y)
  (princ "\nChon duong pline")
  (while (setq en (ssget '((0 . "*POLYLINE"))))
    (foreach en	(vl-remove-if 'listp (mapcar 'cadr (ssnamex en)))
      (setq lay (cdr (assoc 8 (entget en))))
      (setq lsp
	     (mapcar
	       'cdr
	       (vl-remove-if-not '(lambda (x) (= 10 (car x))) (entget en))
	     ) ;_ end of mapcar
      ) ;_ end of setq
      (mapcar
	'(lambda (x y)
	   (setq l (mapcar '- x y))
	   (if (>= (abs (/ (cadr l) (car l))) 0.3) ;DO DOC LON HON 30%
	     (entmakex
	       (append
		 (list (cons 0 "LWPOLYLINE")
		       (cons 100 "AcDbEntity")
		       (cons 100 "AcDbPolyline")
		       (cons 90 2)
		       (cons 8 LAY)
		 ) ;_ end of list
		 (mapcar (function (lambda (p) (cons 10 p))) (LIST X Y))
	       ) ;_ end of append
	     ) ;_ end of entmakex
	   ) ;_ end of if
	 ) ;_ end of lambda
	lsp
	(cdr lsp)
      ) ;_ end of mapcar
      (entdel en)
    ) ;_ end of foreach
  ) ;_ end of while
  (princ)
) ;_ end of defun

Thảo luận gốc

Lisp được chia sẻ trong chủ đề (Đã xong) XIN LISP TÍNH ĐỘ DỐC ĐOẠN THẲNG VÀ XÓA NHỮNG ĐOẠN THẲNG CÓ ĐỘ DỐC THEO ĐIỀU KIỆN. Xem đúng bài viết #439158 để đọc hướng dẫn và trao đổi thêm.

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