Jump to content

lisp copy nội dung text trong một loạt dimenson...


lisp có tác dụng là lọc lấy phần text của tất cả các kích thước m chọn

Cách dùng

  1. Tải tệp 351896_test.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 TEST để chạy lisp.

Mã nguồn 351896_test.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/130437-y%C3%AAu-c%E1%BA%A7u-lisp-copy-n%E1%BB%99i-dung-text-trong-m%E1%BB%99t-lo%E1%BA%A1t-dimenson/

(defun c:test (/ e s p)
  (while (setq s (LM:UnFormat (_sel "\nSelect a Dimension  :") nil))
    (or	(and (setq p (car (entsel "\nSelect a Text/Mtext or <Point>  :")))
	     (wcmatch (cdr (assoc 0 (entget p))) "*TEXT")
	)
	(setq p (cadr (grread t 15 0)))
    )
    (if	(listp p)
      (_text p s)
      (progn (setq e (entget p))
	     (entmod (subst (cons 1 s) (assoc 1 e) e))
	     (entupd (cdr (assoc -1 e)))
      )
    )
  )
  (princ)
)
(defun _text (pt str)
  (entmakex (list (cons 0 "TEXT")
		  (cons 1 str)
		  (cons 10 pt)
		  (cons 40 (getvar 'textsize))		  
	    )
  )
)
(defun _Sel (msg / en el dstr dblk)
  (while
    (progn (setvar 'ERRNO 0)
	   (setq en (car (entsel msg)))
	   (cond
	     ((= 7 (getvar 'ERRNO))
	      (princ "\n--> Missed, Try again.")
	     )
	     ((eq 'ENAME (type en))
	      (if (wcmatch (cdr (assoc 0 (setq el (entget en))))
			   "*DIMENSION"
		  )
		(progn
		  (if (setq dblk (tblobjname "BLOCK" (cdr (assoc 2 el))))
		    (while (and (setq dblk (entnext dblk)) (not dstr))
		      (if (eq "MTEXT" (cdr (assoc 0 (setq el (entget dblk)))))
			(setq dstr (cdr (assoc 1 el)))
		      )
		    )
		  )
		  nil
		)
		(princ "\n--> Invalid Object Selected.")
	      )
	     )
	   )
    )
  )
  dstr
)
;;-------------------=={ UnFormat String }==------------------;;
;;                                                            ;;
;;  Returns a string with all MText formatting codes removed. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  str - String to Process                                   ;;
;;  mtx - MText Flag (T if string is for use in MText)        ;;
;;------------------------------------------------------------;;
;;  Returns:  String with formatting codes removed            ;;
;;------------------------------------------------------------;;
(defun LM:UnFormat ( str mtx / _replace rx )
    (defun _replace ( new old str )
        (vlax-put-property rx 'pattern old)
        (vlax-invoke rx 'replace str new)
    )
    (if (setq rx (vlax-get-or-create-object "VBScript.RegExp"))
        (progn
            (setq str
                (vl-catch-all-apply
                    (function
                        (lambda ( )
                            (vlax-put-property rx 'global     actrue)
                            (vlax-put-property rx 'multiline  actrue)
                            (vlax-put-property rx 'ignorecase acfalse) 
                            (foreach pair
                               '(
                                    ("\032"    . "\\\\\\\\")
                                    (" "       . "\\\\P|\\n|\\t")
                                    ("$1"      . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]")
                                    ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")
                                    ("$1$2"    . "\\\\(\\\\S)|[\\\\](})|}")
                                    ("$1"      . "[\\\\]({)|{")
                                )
                                (setq str (_replace (car pair) (cdr pair) str))
                            )
                            (if mtx
                                (_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str))
                                (_replace "\\"   "\032" str)
                            )
                        )
                    )
                )
            )
            (vlax-release-object rx)
            (if (null (vl-catch-all-error-p str))
                str
            )
        )
    )
)
(vl-load-com)
;|«Visual LISP© Format Options»
(70 2 1 2 nil "_eof " 100 9 0 0 1 T T T T)
;*** DO NOT add text below the comment! ***|;

Thảo luận gốc

Lisp được chia sẻ trong chủ đề (Yêu Cầu) lisp copy nội dung text trong một loạt dimenson.... Xem đúng bài viết #351896 để đọc hướng dẫn và trao đổi thêm.

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