Jump to content

Lisp lệnh QQ trong chủ đề “Làm sao để xoay trục 180 độ mà text không bị ngược?”

Bạn thử cái này.

 
(defun c:qq( / 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 / en eg)
(setq en (entlast)) 
(command "_.leader" rwc pause "" xyp "") 
(while (setq en (entnext en))
(if (= "MTEXT" (cdr (assoc 0 (entget en))))
(setq eg (entget en)
eg (entmod (subst (cons 210 '(0 0 1)) (assoc 210 eg) eg))) 
 )
)
)
 
;;;----------------------------- 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") 
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)
)
 

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 331592_qq.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 QQ để chạy lisp.

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

 
(defun c:qq( / 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 / en eg)
(setq en (entlast)) 
(command "_.leader" rwc pause "" xyp "") 
(while (setq en (entnext en))
(if (= "MTEXT" (cdr (assoc 0 (entget en))))
(setq eg (entget en)
eg (entmod (subst (cons 210 '(0 0 1)) (assoc 210 eg) eg))) 
 )
)
)
 
;;;----------------------------- 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") 
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ủ đề Làm sao để xoay trục 180 độ mà text không bị ngược?. Xem đúng bài viết #331592 để đọc hướng dẫn và trao đổi thêm.

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