Jump to content

Lisp lệnh MIT trong chủ đề “Cho xin lisp chỉnh chữ bị ngược khi MI”


Chào bác TrungNgaMy, anh Duy, bạn ketxu
Lisp ở bài viết số 13 chỉ xử lý với những anh Text bị Mirror thôi chứ chưa xử lý các Text bị Rotate ngược.
Muốn xử lý thêm các anh Text bị Rotate ngược nữa như file ảnh mà bác TrungNgaMy đã upload thì thêm 1 chút nữa vào code

Các bác thử nhé

@foudremars : Lisp xử lý với nhiều đối tượng sẽ làm tăng hiệu quả công việc. Nếu nhieu thì làm bằng tay cũng được, cũng chẳng ảnh hưởng gì đến hoà bình thế giới :undecided:

Cách dùng

  1. Tải tệp 107300_mit.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 MIT để chạy lisp.

Mã nguồn 107300_mit.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/24141-cho-xin-lisp-ch%E1%BB%89nh-ch%E1%BB%AF-b%E1%BB%8B-ng%C6%B0%E1%BB%A3c-khi-mi/
(Defun c:mit (/ luulattext ss i n textent luubatdiem tbTB ll ur ul lr daitext ROSAVE
goctext dainuatext diemquay diemlatx diemlaty DTT TEXT ROTEXT)
(command "undo" "be")
(setq luulattext (getvar "mirrtext"))
(setvar "mirrtext" 1)
(Princ "\nHay chon doi tuong :")
(setq SS (ssget '((0 . "TEXT"))))
(setq i 0)
(setq N (sslength ss))
(while ((setq TEXTENT (ssname SS i))
(setq luubatdiem (getvar "osmode"))
(setvar "osmode" 0)

(setq DTT (entget TEXTENT))
(setq TEXT (cdr (assoc 71 DTT)))
(setq ROSAVE (cdr (assoc 50 DTT)))
(command "ucs" "object" textent)	

(setq tbTB (textbox (list (cons -1 textent)))
ll (car tbTB)
ur (cadr tbTB)
ul (list (car ll) (cadr ur))
lr (list (car ur) (cadr ll))
)

(setq daitext (distance ul lr))
(setq goctext(angle ul lr))
(setq dainuatext (/ daitext 2))
(setq diemquay (polar ul goctext dainuatext))

(if (and (/= ROSAVE 0) (/= ROSAVE pi))
(progn
(command "rotate" textent "" diemquay (/ (* ROSAVE -180) pi))
(command "ucs" "W")
(command "ucs" "object" textent)
) 
)
(setq diemlatx (list (car diemquay) (+ (cadr diemquay) 100)))
(setq diemlaty (list (- (car diemquay) 100) (cadr diemquay)))
(setq DTT (entget TEXTENT))
(setq ROTEXT (cdr (assoc 50 DTT)))
(cond 
((and (= TEXT 2) (= ROTEXT 0)) (command ".mirror" textent "" diemquay diemlatx "y"))
((and (= TEXT 0) (= ROTEXT pi)) (command ".rotate" textent "" diemquay "180"))

((and (= TEXT 2) (= ROTEXT pi)) 
(progn (command ".mirror" textent "" diemquay diemlatx "y")
(command ".rotate" textent "" diemquay "180")
)
)
)
(if (and (/= ROSAVE 0) (/= ROSAVE pi) )
(command "rotate" textent "" diemquay (/ (* ROSAVE 180) pi))
)
;;;;;;;;;;;;;;
(if (and (/= ROSAVE pi) (> ROSAVE (/ pi 2)) (	(command ".rotate" textent "" diemquay "180")
)

(command "ucs" "p")
(setq i (1+ i))
(setvar "osmode"luubatdiem)
)
(setvar "mirrtext" luulattext)
(command "undo" "end")
(Princ)
) 

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Cho xin lisp chỉnh chữ bị ngược khi MI. Xem đúng bài viết #107300 để đọc hướng dẫn và trao đổi thêm.

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