114
1万
中流砥柱
(defun c:test ( / *error* dim fun lst rgx str tag ) (setq tag "dimensions") ;; Tag to update (defun *error* ( msg ) (if (= 'vla-object (type rgx)) (vlax-release-object rgx)) (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))) (princ (strcat "\nError: " msg)) ) (princ) ) (defun sel ( msg prd / ent ) (setq prd (eval prd)) (while (progn (setvar 'errno 0) (setq ent (car (entsel msg))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (null ent) nil) ( (null (prd ent))) ) ) ) ent ) (setq fun '(lambda ( x ) (or (wcmatch (cdr (assoc 0 (entget x))) "*DIMENSION") (prompt "\nInvalid object selected."))) dim (sel "\nSelect first dimension: " fun) ) (cond ( (not dim)) ( (or (null (setq rgx (vl-catch-all-apply 'vlax-get-or-create-object '("vbscript.regexp")))) (vl-catch-all-error-p rgx) ) (princ "\nUnable to interface with RegEx Object.") ) ( t (setq lst (cons (LM:getdimstring dim) lst)) (while (setq dim (sel "\nSelect next dimension <done>: " fun)) (setq lst (cons (LM:getdimstring dim) lst)) ) (setq str (apply 'strcat (cdr (apply 'append (mapcar '(lambda ( x ) (list "*" (LM:quickunformat rgx x))) (reverse lst) ) ) ) ) ) (sel "\nSelect block: " '(lambda ( e / x ) (cond ( (not (and (setq x (entget e)) (= "INSERT" (cdr (assoc 0 x))) (= 1 (cdr (assoc 66 x))) ) ) (prompt "\nSelected object is not an attributed block.") ) ( (LM:setattributevalue e tag str)) ( (prompt (strcat "\nSelected block does not contain the tag "" tag ""."))) ) ) ) ) ) (*error* nil) (princ));; Get Dimension String - Lee Mac;; Returns the displayed content of a dimension(defun LM:getdimstring ( ent / enx rtn ) (if (and (setq enx (entget ent)) (wcmatch (cdr (assoc 0 enx)) "*DIMENSION") (setq ent (tblobjname "block" (cdr (assoc 2 enx)))) (setq ent (entnext ent) enx (entget ent) ) ) (while (and ent (null rtn)) (if (= "MTEXT" (cdr (assoc 0 enx))) (setq rtn (cdr (assoc 1 enx))) ) (setq ent (entnext ent) enx (entget ent) ) ) ) rtn);; Quick Unformat - Lee Mac;; Returns a string with all MText formatting codes removed.;; rgx - [vla] Regular Expressions (RegExp) Object;; str - [str] String to process(defun LM:quickunformat ( rgx str ) (if (null (vl-catch-all-error-p (setq str (vl-catch-all-apply '(lambda nil (foreach pair '( ("\032" . "\\\\\\\")