;;;Sample AutoLISP utility - txtupd.lsp ;; TXTUPD.TXT ; ;; TXTUPD searches for TEXTs, ATTRIBs and ATTDEFs and updates ;; them to the actual values of the text style ;; ;; AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. ;; AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF ;; MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. ;;;DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE ;; UNINTERRUPTED OR ERROR FREE. (defun all_attribs (/ ename_list ss ename enext) (setq ss (ssget "X" '((-4 . "")))) (setq ename_list '()) (if ss ; Check something was found (while (setq ename (ssname ss 0)) (ssdel ename ss) ; remove from ss (while (and (setq ename (entnext ename)) (setq edata (entget ename)) (equal "ATTRIB" (cdr (assoc 0 edata))) ) (setq ename_list (if ename_list (append (list ename) ename_list) (list ename) ) ) ) ;while ) ;while ) ;if ss ename_list ; returns full list ) (defun all_block_texts (/ blkhead ename edata ename_list test_etype) (setq ename_list '()) ; get the first block (setq blkhead (tblnext "BLOCK" 1)) (while blkhead (setq ename (cdr (assoc -2 blkhead))) ; scan through the block an check every entity, whether it is of type text (while ename (setq edata (entget ename)) (if edata (progn (setq test_etype (cdr (assoc 0 edata))) (if (or (equal "TEXT" test_etype) (equal "ATTRIB" test_etype) (equal "ATTDEF" test_etype) ) (progn (setq esc_pfb_do_regen T) (setq ename_list (if ename_list (append (list ename) ename_list) (list ename) ) ) ) ) ; is text ) ) ; edata (setq ename (entnext ename)) ) ; while ename not null (setq blkhead (tblnext "BLOCK")) ) ; while blkhead ename_list ) (defun get_ent_list (/ ename_list ss ename) (setq ss (ssget "X" '((-4 . "")))) (setq ename_list '()) (if ss ; Check something was found (while (setq ename (ssname ss 0)) (ssdel ename ss) ; remove from ss (setq ename_list (if ename_list (append (list ename) ename_list) (list ename) ) ) ) ;while ) ;if ss (setq ename_list (append ename_list (all_block_texts))) (append ename_list (all_attribs)) ; returns full list ) (defun c:TXTUPD (/ ename_list ename edata base_pt style width_def height height_def oblique_def mirror_def count fail_count change_style) ; allow the user to define, which texts of which styles he wants to update (prompt "\nUpdates text written with a text style to the new parameters" ) (setq change_style (getstring "\nType the name of the text style to update (wild-cards are allowed): " ) ) (TXTHGHTFAC) (setq esc_pfb_do_regen nil) (setq count 0 fail_count 0 ename_list (get_ent_list) ) (while (and ename_list (setq ename (car ename_list))) (setq edata (entget ename) style (cdr (assoc 7 edata)) height (cdr (assoc 40 edata)) style_def (tblsearch "style" style) width_def (cdr (assoc 41 style_def)) height_def (cdr (assoc 40 style_def)) oblique_def (cdr (assoc 50 style_def)) ; it is only one flag, that defines backward and upside-down mirror_def (cdr (assoc 71 style_def)) ) ; some of the values have default values and are assumed to be 0 if they ; do not show up on the list (if (= oblique_def nil) (setq oblique_def 0.0) ) (if (= mirror_def nil) (setq mirror_def 0.0) ) ; only update, if one of the selected styles (if (wcmatch style (strcase change_style)) (progn (setq height (* esc_pfb_conv_scale_factor height)) (setq new_edata (subst (cons 40 height) (assoc 40 edata) edata)) (setq new_edata (subst (cons 41 width_def) (assoc 41 new_edata) new_edata) ) (setq new_edata (subst (cons 51 oblique_def) (assoc 51 new_edata) new_edata) ) (setq new_edata (subst (cons 71 mirror_def) (assoc 71 new_edata) new_edata) ) (if (entmod new_edata) (setq count (+ 1 count)) (progn (setq fail_count (+ 1 fail_count)) (princ "\nERROR :\n") (princ (setq err_data new_edata)) (princ "\nERRNO :") (princ (setq err (getvar "ERRNO"))) (princ "\n\n") ) ) ) ) (setq ename_list (cdr ename_list)) ) ; give some statistical output (princ (strcat "\n" (itoa count) " objects changed")) (princ (strcat "\n" (itoa fail_count) " object changes failed") ) (if esc_pfb_do_regen (progn (princ "\nChanged blocked entities so ...") (command "_.REGEN") ) ) (princ "\ndone\n") (princ) ) (defun TXTHGHTFAC (/ temp strPrompt) (prompt "\nEnter multiplicator for all text height, 1 for no changes " ) (setq strPrompt (strcat "\nEnter new scale factor <" (rtos esc_pfb_conv_scale_factor) "> :" ) ) (setq temp (getreal strPrompt)) (if (= (type temp) 'REAL) (progn (setq esc_pfb_conv_scale_factor temp) (princ "\nScale factor set to ") (prin1 esc_pfb_conv_scale_factor) ) ) (princ) ) (setq esc_pfb_conv_scale_factor 1.0) ; The default value for the scale factor (PRINC "\nUse c:TXTUPD to convert the TEXT, ATTRIB and ATTDEF entities" ) (princ)