我不记得从哪里得到这个代码,但我一直在使用它:
- (defun c:txt2dim (/ edim text etxt vla_dim cmd1)
- (prompt "\nText to Dimension")
- (setq cmd1 (getvar 'cmdecho))
- (setvar 'cmdecho 0)
- (vl-load-com)
- (while
- (or (initget 1)
- (not (setq edim (entsel "\nSelect dimension: ")))
- (/= (cdr (assoc 0 (entget (car edim)))) "DIMENSION")
- )
- (prompt "\n*** You must select a dimension. ***")
- )
- (while
- (and
- (not
- (and (setq etxt (entsel "\nSelect text to add to override or enter to type: "))
- (= (cdr (assoc 0 (entget (car etxt)))) "TEXT")
- )
- )
- (or (initget 1)
- (not
- (setq text (getstring t "\nType the text or ENTER to clear override: "))
- )
- )
- )
- )
- (if etxt
- (setq text (vla-get-textstring (vlax-ename->vla-object (car etxt))))
- )
- (setq vla_dim (vlax-ename->vla-object (car edim)))
- (cond
- ((and text (/= text ""))
- (vla-put-textoverride vla_dim (strcat (chr 60)(chr 62) "[url="file://\\X"]\\X[/url]" text))
- )
- ((and text (= text "")) ; clear the override
- (vla-put-textoverride vla_dim text)
- )
- )
- (setvar 'cmdecho cmd1)
- (princ)
- )
|