Revised for bug fix.
;; Multi Tab Text Insert/Edit
;; By Jeff Mishler
;;
;; Places text into all PS layouts - PSText.lsp
;; To revise, use the PSText-edit.lsp command.
;; When adding text:
;; Uses current text style, and current layer
;; Uses current text style text size, if 0 uses sys var TextSize
;; Copying existing Text,Mtext,or Rtext uses existing attributes
;; Edit routine does not handle Rtext
;;
;;
;; Modified by Charles Alan Butler 05/23/04 - 06/18/04
;; added paperspace check & user input error check
;; added close active viewport
;; added allow spaces in user text string
;; added ability to pick existing text in ps to insert in layouts
;; added Line Text Edit to pstext-edit
;; Modified by CAB 06/17/04
;; added use of text rotation
;; Modified by CAB 06/18/04
;; revised the text copy process to copy all attributes of the selected text
;; revised both routines to handle MTEXT & add routine to handle RTEXT
;; 11/04/2004 CAB bug fix, 2 copies in original tab, fixed
(defun c:pstext (/ str pt txt_ht elst ent cnt tab newent rot yesno loop ctab)
(if (= (getvar "tilemode") 1)
(alert "\nYou must be in Paper Space to run this routine.\t")
(progn ; else you are in paper space, ok to proceed
(if (/= (getvar "cvport") 1); a view port is active
(command "_pspace") ; close the view port
)
(prompt "\nSelect nothing or ENTER to type the text: ")
(setq loop t)
(while loop
(setq ent (entsel "\nSelect text to place on all PS layouts: "))
(cond
((null ent) (setq loop nil)); exit on nothing selected
((= (cdr (assoc 0 (setq elst (cdr(entget (car ent)))))) "RTEXT")
(INITGET "Yes No")
(setq yesno
(getKword
(strcat "\nRTEXT selected, you can copy but not edit this type."
" Continue <Yes>/No: ")))
(if (/= yesno "No")
(setq loop nil); got text, so exit loop
(setq elst nil)
)
)
((member (cdr (assoc 0 elst))'("MTEXT" "TEXT"))
(setq loop nil); got text, so exit loop
)
((prompt "\nNot a TEXT object, Try Again."))
); end cond
) ; end while
(if (and
(null ent) ; no text selected, so get user input
(/= (setq str
(getstring t "\nEnter the Text to place on all PS layouts: ")) "")
(setq pt (getpoint "\nSelect or Enter common insertion Point: "))
)
(progn
(if (null (setq ang (getangle "\nSelect or Enter text angle: <0>")))
(setq ang 0)
)
;; If text height is undefined (signified by 0 in the table)
(if (= (cdr (assoc 40 (tblsearch "style" (getvar "textstyle")))) 0)
(command "text" pt "" ang str)
(command "text" pt ang str)
) ; endif
(setq elst (entget (entlast)))
) ; progn
) ; endif (null ent)
(if elst
(progn
(setq cnt 0
ctab (getvar "CTab"))
(foreach tab (layoutlist)
(if (and (/= (strcase tab) "MODEL")
(/= tab ctab))
(progn
(setq newent (subst (cons 410 tab) (assoc 410 elst) elst))
(entmake newent)
(setq cnt (1+ cnt))
)
)
)
(prompt (strcat "\n" (itoa cnt) " Layouts Updated."))
) ; progn
(prompt "\nUser Quit.")
) ; endif
) ; progn
) ;endif
(princ)
); end defun
(prompt "\nEnter psText to add text.")
(defun c:pstext-edit (/ str pt ent oldstr cnt)
(vl-load-com)
(defun get_point (e)
;; get a referance point to compare, if dtext use alignment point
;; because center justification can change the insertion point
(if (= (vla-get-objectname e) "AcDbText")
(vlax-get e "textalignmentpoint")
(vlax-get e "insertionpoint")
)
)
(if (= (getvar "tilemode") 1)
(alert "\nYou must be in Paper Space to run this routine.\t")
(progn ; else you are in paper space, ok to proceed
(if (/= (getvar "cvport") 1); a view port is active
(command "_pspace") ; close the view port
)
(princ "\nSelect text to revise in all PS layouts: ")
(if (setq ss (ssget ":S" '((0 . "TEXT,MTEXT"))))
(progn
(setq ent (vlax-ename->vla-object (ssname ss 0))
oldstr (vlax-get ent "textstring")
pt (get_point ent)
cnt 1
)
(command "_.ddedit" (ssname ss 0) "")
(if (= (setq str (vlax-get ent "textstring")) oldstr)
(prompt "\nNo change in text, nothing to do.")
(progn ; step through all layouts
(vlax-for x (vla-get-layouts
(vla-get-activedocument
(vlax-get-acad-object)
)
)
;; skip model space
(if (not (wcmatch (strcase (vla-get-name x)) "MODEL"))
(vlax-for y (vla-get-block x)
(if
(and
(member (vla-get-objectname y) '("AcDbMText" "AcDbText"))
(= (vla-get-textstring y) oldstr)
(= (car pt)(car (get_point y)))
(= (cadr pt)(cadr (get_point y)))
)
(progn
(vla-put-textstring y str)
(setq cnt (1+ cnt))
)
) ; endif
) ; vlax-for
) ; endif
) ; vlax-for
(vlax-release-object ent)
(prompt (strcat "\n" (itoa cnt) " Layouts Updated."))
); progn
); endif
) ; progn
(prompt "\nObject is not plain text or Mtext.")
) ; endif
) ; progn
) ;endif
(princ)
) ; defun
(prompt "\nEnter psText-edit to edit text.")