Jump to content

Viết tên layer của Line và ghi ra màn hình



- Ghi ra màn hình Layer của Line(s) tại vị trí trung điểm
- Trong lisp kèm thêm 2 lisp nhỏ theo yêu cầu riêng

Cách dùng

  1. Tải tệp 190555_test1_test2_test3.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 TEST1 TEST2 TEST3 để chạy lisp.

Mã nguồn 190555_test1_test2_test3.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/62093-y%C3%AAu-c%E1%BA%A7u-vi%E1%BA%BFt-t%C3%AAn-layer-v%C3%A0-offset-m%E1%BB%99t-kho%E1%BA%A3ng-a-khi-click-v%C3%A0o-m%E1%BB%99t-line/
;1
(defun c:Test1(/ adoc msp ang)
(vl-load-com)
(alert "\n@Ketxu t\U+1EB7ng xuanhaoxd")
(or #h (setq #h 1))
(or #of (setq #of 1))
(setq  aDoc (vla-get-ActiveDocument (vlax-get-acad-object))
 msp (vla-get-modelspace adoc)
 #h (cond ((getreal (strcat "Chieu cao chu <" (rtos #h 2 1) "> :")))(#h))
 #of (cond ((getreal (strcat "Khoang offset <" (rtos #of 2 2) "> :")))(#of))
)
(prompt "\nChon Line(s) :")
(ssget (list (cons 0 "LINE")))
(vlax-for eLine (vla-get-ActiveSelectionSet aDoc)
(setq ang (reAng (angle (vlax-get eLine 'StartPoint) (vlax-get eLine 'EndPoint))))
(vla-put-Rotation
;AddText
(vla-addtext msp (vla-get-Layer eLine)
 ;MidPoint
 (vlax-3d-point
  (polar
  ((lambda(a B)(mapcar '* (mapcar '+ a B) '(0.5 0.5 0.5)))
(vlax-get eLine 'StartPoint)
(vlax-get eLine 'EndPoint)
  )
  (+ ang (* pi 0.5))
  #of
  )
 )
 #h
)
ang
)
)
)
;2
(defun c:Test2(/ adoc msp ang)
(vl-load-com)
(alert "\n@Ketxu t\U+1EB7ng xuanhaoxd")
(or #h (setq #h 1))
(or #of (setq #of 1))
(setq  aDoc (vla-get-ActiveDocument (vlax-get-acad-object))
 msp (vla-get-modelspace adoc)
 #h (cond ((getreal (strcat "Chieu cao chu <" (rtos #h 2 1) "> :")))(#h))
 #of (cond ((getreal (strcat "Khoang offset <" (rtos #of 2 2) "> :")))(#of))
)
(prompt "\nChon Line(s) :")
(ssget (list (cons 0 "LINE")))
(vlax-for eLine (vla-get-ActiveSelectionSet aDoc)
(setq ang (reAng (angle (vlax-get eLine 'StartPoint) (vlax-get eLine 'EndPoint))))
(vla-put-Rotation
;AddText
(vla-addtext msp (strcat  "%%c" (parse (vla-get-Layer eLine)))
 ;MidPoint
 (vlax-3d-point
  (polar
  ((lambda(a B)(mapcar '* (mapcar '+ a B) '(0.5 0.5 0.5)))
(vlax-get eLine 'StartPoint)
(vlax-get eLine 'EndPoint)
  )
  (+ ang (* pi 0.5))
  #of
  )
 )
 #h
)
ang
)
)
)
;3
(defun c:Test3 ( / lay_col lay_nm lay)
(vl-load-com)
(alert "\n@Ketxu t\U+1EB7ng xuanhaoxd")
(setq lay_col (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
(vlax-for lay lay_col
(setq lay_nm (vla-get-name lay))
(if (and (< (strlen lay_nm) 9) (not (zerop (atof lay_nm))))
 (vla-put-name lay (parse lay_nm))
)
)
(vlax-release-object lay_col)
(princ)
)
(defun Pur0 (x / sth)
(strcat (substr x 1 (1- (strlen x)))
 (if (= (setq sth (substr x (strlen x))) "0") ""
  (strcat "." sth))
))
(defun Pur0 (a / x)
(if (zerop (rem (atoi a) 10))
(itoa (/ (atoi a) 10))
(rtos (/ (distof a) 10) 2 1)
))
(defun Parse (str)
(strcat
 (pur0 (substr str 1 (- (strlen str) 3)))
 "x"
 (pur0 (substr str (- (strlen str) 2)))
)
)
;18300450
(defun ReAng ( a )
 ( (lambda ( a ) (if (and (< (/ pi 2.0) a) (<= a (/ (* 3.0 pi) 2.0))) (+ a pi) a))
(rem (+ a pi pi) (+ pi pi))
 )
)
(setvar "modemacro" "\n@Ketxu t\U+1EB7ng xuanhaoxd")

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [ yêu cầu] Viết tên layer và offset một khoảng a khi click vào một line. Xem đúng bài viết #190555 để đọc hướng dẫn và trao đổi thêm.

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