 ; VBMX - middle rejustify a column of text.  Change existing entities rather
 ; than replacing them - useful when style, layer etc. must be preserved.
 ; Copyright 1995 by Rocket Software
 ;
 (DEFUN C:VBMX (/ ss cc rr xa num enam entt pty pa sp)
  (setvar "cmdecho" 0)
  (command "undo" "mark")
  (prompt "Pick text/attdefs to middle rejustify: ")
  (if (setq ss (ssget '((-4 . "<or")
                        (0 . "text")
                        (0 . "attdef")
                        (-4 . "or>"))))
      (progn
           (setq cc (getpoint "Pick one side: "))
           (setq rr (getpoint cc "\n...and the other side or <Return>:"))
           (if rr 
              (setq xa (/ (+ (car cc) (car rr)) 2))
              (setq xa (car cc)))
           (setq num 0)
           (while (setq enam (ssname ss num))
                  (setq num (1+ num))
                  (setq entt (entget enam))            ; get entity data
                  (setq ten (cdr (assoc 10 entt)))     ; save 10 point
                  (if (= typ "ATTDEF")
                      (setq entt (subst (cons 74 0) (assoc 74 entt) entt))
                      (setq entt (subst (cons 73 0) (assoc 73 entt) entt)))
                  (entmod (subst (cons 72 4) (assoc 72 entt) entt))  ; change
                  (setq entt (entget enam))            ; get changed edata
                  (setq new10 (cdr (assoc 10 entt)))   ; new 10 point
                  (setq dist (distance ten new10))     ; distance moved
                  (setq angl (angle new10 ten))        ; and angle
                  (setq new11 (cdr (assoc 11 entt)))   ; new middle point
                  (setq new11 (polar new11 angl dist)) ; move middle as 10 was
                  (entmod (subst (cons 11 new11) (assoc 11 entt) entt))
                  (setq entt (entget enam))            ; get entity data
                  (setq pty (cddr (assoc 11 entt)))    ; final middle y coord
                  (setq pa (cons xa pty))              ; final middle point
                  (entmod (subst (cons 11 pa) (assoc 11 entt) entt)))
           (setq sp (if (= (setq num (sslength ss)) 1) "" "s"))
           (prompt (strcat "\n" (itoa num) " line" sp " middle rejustified.")))
      (prompt "\nNo text selected."))
 (princ))