Jump to content

Lisp lệnh TD trong chủ đề “nhờ các bác viết giúp e lips pick 1 điểm xuất ra tọa độ dưới dạng (x;y)”

 

Có phải như vầy không.

 

 
(defun c:td( / get-x get-y oce xp yp rwc )
(setq oce (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setvar "luprec" 4)
(main)
(setvar "cmdecho" oce)
)
 
;;;----------------------------- Leader Placement Routine ---------------------
;;; Here is where the leaders are actually written to the database
;;; based upon the value of coordinates passed from module "MAIN" .
;;; Null points are ignored.
 
(defun do_put_leader( xyp )
(command "_.leader" rwc pause "" xyp "")
)
 
;;;----------------------------- xyz coordinate breakdown ----------------------
;;; This routine accepts a point from the calling function and breaks it down
;;; into X,Y values.
 
(defun get_xyz ( pt )
  (strcat "(" (rtos (* 0.001 (car pt)) 2 3) ";" (rtos (* 0.001 (cadr pt)) 2 3) ")"))
 
 
;;;-------------------Secondary main module------------------------------------
;;; Accepts the user input and allows the user to select many objects in
;;; succession.
 
(defun main()
(setq olddim (getvar "dimstyle"))
(setq a (getreal "\n Input Text Height for Annotation : <2.5> "))
(if (null a) (setq a 2.5))
(setvar "dimtxt" a)
  
(while (setq rwc (getpoint "\nSelect point: "))
  (do_put_leader (get_xyz rwc)) 
)
(command "dimstyle" "restore" olddim)
)
 

e cám ơn bác rất nhiều. đúng là lips e cần. bác rảnh ko hôm nào đi uống bia với e nhé. e ở chợ Phùng Khoang. :v

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 295436_td.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 TD để chạy lisp.

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

 
(defun c:td( / get-x get-y oce xp yp rwc )
(setq oce (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setvar "luprec" 4)
(main)
(setvar "cmdecho" oce)
)
 
;;;----------------------------- Leader Placement Routine ---------------------
;;; Here is where the leaders are actually written to the database
;;; based upon the value of coordinates passed from module "MAIN" .
;;; Null points are ignored.
 
(defun do_put_leader( xyp )
(command "_.leader" rwc pause "" xyp "")
)
 
;;;----------------------------- xyz coordinate breakdown ----------------------
;;; This routine accepts a point from the calling function and breaks it down
;;; into X,Y values.
 
(defun get_xyz ( pt )
  (strcat "(" (rtos (* 0.001 (car pt)) 2 3) ";" (rtos (* 0.001 (cadr pt)) 2 3) ")"))
 
 
;;;-------------------Secondary main module------------------------------------
;;; Accepts the user input and allows the user to select many objects in
;;; succession.
 
(defun main()
(setq olddim (getvar "dimstyle"))
(setq a (getreal "\n Input Text Height for Annotation : <2.5> "))
(if (null a) (setq a 2.5))
(setvar "dimtxt" a)
  
(while (setq rwc (getpoint "\nSelect point: "))
  (do_put_leader (get_xyz rwc)) 
)
(command "dimstyle" "restore" olddim)
)
 

Thảo luận gốc

Lisp được chia sẻ trong chủ đề nhờ các bác viết giúp e lips pick 1 điểm xuất ra tọa độ dưới dạng (x;y). Xem đúng bài viết #295436 để đọc hướng dẫn và trao đổi thêm.

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