Jump to content

Lisp lệnh GDCPL trong chủ đề “Cao độ của đường LWPOLYLINE”

Bạn làm cách này được không nhé.

Từ các đường đồng mức có cao độ. Bạn dùng lisp dưới đây để ghi cao độ của Pline. 

Bạn sẽ nhập khoảng cách giữa các cao độ trên cùng 1 Pline.

Như vậy mỗi đường đồng mức ta đều có số liệu cao độ rồi. 

Từ số liệu này ta có thể chạy tạo lại đường đồng mức 1 m dễ dàng.

Code của bạn đây

(defun c:GDCPL( / olmode ss KCL h en CDPline n i Pnt1)
(vl-load-com)
(setvar "CMDECHO" 0)
(setq olmode (getvar "OSMODE"))
(setvar "OSMODE" 0)
(setq ss (ssget  (list (cons 0 "POLYLINE,LWPOLYLINE"))))
(setq KCL (getreal "\n Nhap khoang cach can ghi cao do:  "))
(setq h (getreal "\n Nhap chieu cao Text cao do:  "))

(foreach en (acet-ss-to-list ss)
  	(progn
		(setq CDPline (Length1  en))
		(setq n (fix (/ CDPline KCL)))
		(setq i 1)
		(while (<= i n)
			(setq pnt1 (vlax-curve-getPointAtDist en (* i KCL)))
			(MakeText pnt1 (rtos (caddr Pnt1) 2 2) h 0 "L") 
		  	(setq i (1+ i))
		)
	  )
)
(setvar "osmode" olmode)
(princ)
)
(defun Length1 (e) (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)))
  
(defun MakeText (point string Height Ang justify / Lst); Ang: Radial
(setq Lst (list '(0 . "TEXT")
								(cons 10 point)
								(cons 40 Height)
								(cons 1 string)
								(if Ang (cons 50 Ang))
								
								
		)
	justify (strcase justify)
)
(cond ((= justify "C") (setq Lst (append Lst (list (cons 72 1) (cons 11 point)))))
			((= justify "R") (setq Lst (append Lst (list (cons 72 2) (cons 11 point)))))
			((= justify "M") (setq Lst (append Lst (list (cons 72 4) (cons 11 point)))))
			((= justify "TL") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 3)))))
			((= justify "TC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 3)))))
			((= justify "TR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 3)))))	
			((= justify "ML") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 2)))))
			((= justify "MC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 2)))))
			((= justify "MR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 2)))))
			((= justify "BL") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 1)))))
			((= justify "BC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 1)))))
			((= justify "BR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 1))))))
(entmakex Lst)
)

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

  1. Chép mã nguồn, lưu thành tệp 296486_gdcpl.lsp.
  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 GDCPL để chạy lisp.

Mã nguồn 296486_gdcpl.lsp (trích từ bài viết gốc)

(defun c:GDCPL( / olmode ss KCL h en CDPline n i Pnt1)
(vl-load-com)
(setvar "CMDECHO" 0)
(setq olmode (getvar "OSMODE"))
(setvar "OSMODE" 0)
(setq ss (ssget  (list (cons 0 "POLYLINE,LWPOLYLINE"))))
(setq KCL (getreal "\n Nhap khoang cach can ghi cao do:  "))
(setq h (getreal "\n Nhap chieu cao Text cao do:  "))

(foreach en (acet-ss-to-list ss)
  	(progn
		(setq CDPline (Length1  en))
		(setq n (fix (/ CDPline KCL)))
		(setq i 1)
		(while (<= i n)
			(setq pnt1 (vlax-curve-getPointAtDist en (* i KCL)))
			(MakeText pnt1 (rtos (caddr Pnt1) 2 2) h 0 "L") 
		  	(setq i (1+ i))
		)
	  )
)
(setvar "osmode" olmode)
(princ)
)
(defun Length1 (e) (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)))
  
(defun MakeText (point string Height Ang justify / Lst); Ang: Radial
(setq Lst (list '(0 . "TEXT")
								(cons 10 point)
								(cons 40 Height)
								(cons 1 string)
								(if Ang (cons 50 Ang))
								
								
		)
	justify (strcase justify)
)
(cond ((= justify "C") (setq Lst (append Lst (list (cons 72 1) (cons 11 point)))))
			((= justify "R") (setq Lst (append Lst (list (cons 72 2) (cons 11 point)))))
			((= justify "M") (setq Lst (append Lst (list (cons 72 4) (cons 11 point)))))
			((= justify "TL") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 3)))))
			((= justify "TC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 3)))))
			((= justify "TR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 3)))))	
			((= justify "ML") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 2)))))
			((= justify "MC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 2)))))
			((= justify "MR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 2)))))
			((= justify "BL") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 1)))))
			((= justify "BC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 1)))))
			((= justify "BR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 1))))))
(entmakex Lst)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Cao độ của đường LWPOLYLINE. Xem đúng bài viết #296486 để đọc hướng dẫn và trao đổi thêm.

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