Jump to content

Recommended Posts

Posted

hello all:

Can someone help me modify this routine?

This routine adds a line about texts and mtexs and it is very helpful to me but sometimes instead of texts or mtext I have dimensions

I would like the routine when selecting and detecting dimensions to also add a line above its value.

 

I hope someone knows.

image.png.cf57818064e81e01f38938f1a97e7a32.png

 

here the code

(defun c:ltx (/ o s)
  (if (setq s (ssget ":L" '((0 . "*TEXT"))))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (setq o (vlax-ename->vla-object e))
      (if (= "TEXT" (cdr (assoc 0 (entget e))))
	(vla-put-textstring o (strcat "%%O" (vl-string-left-trim "%%O" (vla-get-textstring o))))
	(vla-put-textstring o (strcat "\\O" (vl-string-left-trim "\\O" (vla-get-textstring o))))
      )
    )
  )
  (princ)
)

thanks

 

Posted (edited)

@leonucadomi Try This:

;; original code by RonJonP, edited by P. Kenewell
(defun c:ltx (/ o s)
  (command "._undo" "_be")
  (if (setq s (ssget ":L" '((0 . "*TEXT,DIMENSION"))))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (setq o (vlax-ename->vla-object e))
      (cond
         ((= "TEXT" (cdr (assoc 0 (entget e))))
            (vla-put-textstring o (strcat "%%U%%O" (vl-string-left-trim "%%U%%O" (vla-get-textstring o))))
         )
         ((= "MTEXT" (cdr (assoc 0 (entget e))))
            (vla-put-textstring o (strcat "\\L\\O" (vl-string-left-trim "\\L\\O" (vla-get-textstring o))))
         )
         ((= "DIMENSION" (cdr (assoc 0 (entget e))))
            (if (= (vla-get-textoverride o) "")
               (vla-put-textoverride o "\\L\\O<>")
               (vla-put-textoverride o (strcat "\\L\\O" (vl-string-left-trim "\\L\\O" (vla-get-textoverride o))))
            )
         )
      )
    )
  )
  (command "._undo" "_end")
  (princ)
)

 

Edited by pkenewell
Added Undo marks
  • Thanks 1
Posted (edited)

@leonucadomi Actually - I think this version will work better i it will prevent it from stripping other formatting for the reason Lee Mac noted here:

; Original by RonJonP, edited by P. Kenewell
(defun c:ltx (/ o s)
  (setvar "cmdecho" 0)
  (command "._undo" "_be")
  (if (setq s (ssget ":L" '((0 . "*TEXT,DIMENSION"))))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (setq o (vlax-ename->vla-object e))
      (cond
         ((= "TEXT" (cdr (assoc 0 (entget e))))
            (vla-put-textstring o
               (strcat "%%U%%O"
                  (vl-string-subst "" "%%U"
                     (vl-string-subst "" "%%O" (vla-get-textstring o))
                  )
               )
            )
         )
         ((= "MTEXT" (cdr (assoc 0 (entget e))))
            (vla-put-textstring o
               (strcat "\\L\\O"
                  (vl-string-subst "" "\\L" 
                     (vl-string-subst "" "\\O" (vla-get-textstring o))
                  )
               )
            )
         )
         ((= "DIMENSION" (cdr (assoc 0 (entget e))))
            (if (= (vla-get-textoverride o) "")
               (vla-put-textoverride o "\\L\\O<>")
               (vla-put-textoverride o
                  (strcat "\\L\\O"
                     (vl-string-subst "" "\\L" 
                        (vl-string-subst "" "\\O" (vla-get-textoverride o))
                     )
                  )
               )
            )
         )
      )
    )
  )
  (command "._undo" "_end")
  (setvar "cmdecho" 1)
  (princ)
)

 

Edited by pkenewell
  • Like 1
  • Thanks 1
Posted

 

THANK YOU THIS IS PRECISELY WHAT I NEEDED

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...