Jump to content

Lisp lệnh GPMB trong chủ đề “LISP GPMB”

Bạn thử lại code này nhé:

(DEFUN C:gpmb(/ TH SS Index PtIns Ent PtM PtL PtR SSL SSR LenSSL LenSSR LstPtXL LstPtXR
		  XL XR YL YR I PtDimLine) 
(ACET-ERROR-INIT (LIST (LIST "OSMODE" 0 "CLAYER" "DIM" "CMDECHO" 0) T))
(setq TH (getstring "\nChoòn trýõÌng hõòp: "))
(setq ss (ssget "X" '((0 . "INSERT") (2 . "Dau_co")))
	  Index 0)
  (while (setq Ent (ssname ss Index))
	(setq PtIns (cdr (assoc 10 (entget ent)))	
	  PtM (polar PtIns (/ pi 2) -10))
	(command "Zoom" "c" PtM 25)
	(setq PtL (polar PtM pi 20);Dieu chinh cho nay cho phu hop
	  PtR (polar PtM 0 20)
	  PtM (polar PtM (/ pi 2) 1)
	  SSL (ssget "c" PtM PtL '((0 . "LINE") (8 . "ENTTNTHIETKE")))
	  SSR (ssget "c" PtM PtR '((0 . "LINE") (8 . "ENTTNTHIETKE")))
	  Index (1+ Index))
	(setq LenSSL (sslength SSL)
	  I 0
	  LstPtXL Nil)
	(while (< I LenSSL)
	  (Setq LstPtXL (append LstPtXL (list(cadr (assoc 10 (entget (ssname SSL I)))))) I (1+ I))
	)
	(Setq XL (nth 0 (vl-sort LstPtXL '<)))
	(setq LenSSR (sslength SSR)
	  I 0
	  LstPtXR Nil)
	(while (< I LenSSR)
	  (Setq LstPtXR (append LstPtXR (list(cadr (assoc 10 (entget (ssname SSR I)))))) I (1+ I))
	)
	(Setq XR (nth 0 (vl-sort LstPtXR '>)))
	(setq I 0)
	(while (< I LenSSL)
	  (if (= (cadr (assoc 10 (entget (ssname SSL I)))) XL)
	(setq YL  (caddr (assoc 10 (entget (ssname SSL I)))))
	  )
	  (setq I (1+ I))
	)
	(setq I 0)
	(while (< I LenSSR)
	  (if (= (cadr (assoc 10 (entget (ssname SSR I)))) XR)
	(setq YR  (caddr (assoc 10 (entget (ssname SSR I)))))
	  )
	  (setq I (1+ I))
	)	
	(setq PtL (polar (list XL YL 0.0) pi 1.5))
	(if (= TH "1")
	  (setq PtR (polar (list XR YR 0.0) 0 1.5))
	  (setq PtR (list XR YR 0.0))
	)
	(command "Insert" "GPMB" PtL "" "" "" )
	(command "Insert" "GPMB" PtR "" "" "")
	(command "mirror" "l" "" PtR (polar PtR (/ pi 2) 5) "y")	
	(setq PtM (polar PtM (/ pi 2) 5)
	  PtL (list (car PtL) (cadr PtM) 0.0)
	  PtR (list (car PtR) (cadr PtM) 0.0) 
	  PtDimLine (polar PtM (/ Pi 2) 2))
	(command "_dimlinear" PtL PtM PtDimLine)
	(command "_dimlinear" PtM PtR PtDimLine)  
  )
  (command "zoom" "e")
  (acet-error-restore)
)
Có thay đổi: Bạn chỉ cần tạo một khối mốc lộ giới Trái với tên GPMB, tôi dx bổ sung chức năng Mirror để chuyển nó sang bên phải.

Lưu ý: - Điểm chèn (Insert Point) của Block đặt trong Block đừng để xa tít mù tắp như cái Block GPMB ban đầu cảu bạn. Vì rất khó xác định điểm chèn Block trên mặt đất tự nhiên nên tôi chỉ xác định được cao độ của chân đường đắp hoặc đỉnh đường đào thôi.

- Vùng chọn các đối tượng tôi tính từ tâm ra mỗi phía 20m nên nếu các trắc ngang có khoảng cách từ tim đến chân đường đắp hoặc đỉnh đường đào lớn hơn 20m thì sẽ ko xác định được, nếu có chỗ nào lớn hơn thì chuyển riêng trắc đó vào một file và chỉnh các dòng như chú thích trong code cho phù hợp, không chỉnh tổng thể vì sẽ dễ bị chọn nhầm sang các trắc khác.

 

Mình đang dùng lisp này của bạn, các trắc ngang khác không sao đến mấy trắc ngang mình up dưới đây lại lỗi. Bro nào tiện đường đi qua xem giúp mình với nhé

Thank!

Lisp: https://www.cadviet.com/upfiles/5/64560_gpmb.lsp

DWG: https://www.cadviet.com/upfiles/5/64560_test_1.dwg

Cách dùng

  1. Tải tệp 396998_gpmb.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 GPMB để chạy lisp.

Mã nguồn 396998_gpmb.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/17984-lisp-gpmb/
(DEFUN C:gpmb(/ TH SS Index PtIns Ent PtM PtL PtR SSL SSR LenSSL LenSSR LstPtXL LstPtXR
		  XL XR YL YR I PtDimLine) 
(ACET-ERROR-INIT (LIST (LIST "OSMODE" 0 "CLAYER" "DIM" "CMDECHO" 0) T))
(setq TH (getstring "\nChoòn trýõÌng hõòp: "))
(setq ss (ssget "X" '((0 . "INSERT") (2 . "Dau_co")))
	  Index 0)
  (while (setq Ent (ssname ss Index))
	(setq PtIns (cdr (assoc 10 (entget ent)))	
	  PtM (polar PtIns (/ pi 2) -10))
	(command "Zoom" "c" PtM 25)
	(setq PtL (polar PtM pi 20);Dieu chinh cho nay cho phu hop
	  PtR (polar PtM 0 20)
	  PtM (polar PtM (/ pi 2) 1)
	  SSL (ssget "c" PtM PtL '((0 . "LINE") (8 . "ENTTNTHIETKE")))
	  SSR (ssget "c" PtM PtR '((0 . "LINE") (8 . "ENTTNTHIETKE")))
	  Index (1+ Index))
	(setq LenSSL (sslength SSL)
	  I 0
	  LstPtXL Nil)
	(while (< I LenSSL)
	  (Setq LstPtXL (append LstPtXL (list(cadr (assoc 10 (entget (ssname SSL I)))))) I (1+ I))
	)
	(Setq XL (nth 0 (vl-sort LstPtXL '<)))
	(setq LenSSR (sslength SSR)
	  I 0
	  LstPtXR Nil)
	(while (< I LenSSR)
	  (Setq LstPtXR (append LstPtXR (list(cadr (assoc 10 (entget (ssname SSR I)))))) I (1+ I))
	)
	(Setq XR (nth 0 (vl-sort LstPtXR '>)))
	(setq I 0)
	(while (< I LenSSL)
	  (if (= (cadr (assoc 10 (entget (ssname SSL I)))) XL)
	(setq YL  (caddr (assoc 10 (entget (ssname SSL I)))))
	  )
	  (setq I (1+ I))
	)
	(setq I 0)
	(while (< I LenSSR)
	  (if (= (cadr (assoc 10 (entget (ssname SSR I)))) XR)
	(setq YR  (caddr (assoc 10 (entget (ssname SSR I)))))
	  )
	  (setq I (1+ I))
	)	
	(setq PtL (polar (list XL YL 0.0) pi 1.5))
	(if (= TH "1")
	  (setq PtR (polar (list XR YR 0.0) 0 1.5))
	  (setq PtR (list XR YR 0.0))
	)
	(command "Insert" "GPMB" PtL "" "" "" )
	(command "Insert" "GPMB" PtR "" "" "")
	(command "mirror" "l" "" PtR (polar PtR (/ pi 2) 5) "y")	
	(setq PtM (polar PtM (/ pi 2) 5)
	  PtL (list (car PtL) (cadr PtM) 0.0)
	  PtR (list (car PtR) (cadr PtM) 0.0) 
	  PtDimLine (polar PtM (/ Pi 2) 2))
	(command "_dimlinear" PtL PtM PtDimLine)
	(command "_dimlinear" PtM PtR PtDimLine)  
  )
  (command "zoom" "e")
  (acet-error-restore)
)

Thảo luận gốc

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

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