Nikon Posted December 30, 2024 Posted December 30, 2024 (edited) Hi, everybody. Happy New Year! If I use these lines, the code works: ;(setq ss (ssget "_X" '((0 . "*TEXT"))) i -1) ; select all texts (setq ss (ssget '((0 . "*TEXT"))) i -1) ; if you do not need to select the entire text If I replace them with: (initget "All Select") (setq select (getkword "\nSelect text to change [All/Select] <Select> : ")) (if select (cond ( (= select "All") (setq SS (ssget "_X" '((0 . "MTEXT")))) ) ( (= select "Select") (setq SS (ssget "_:L")) ) ) (setq SS (ssget "_:L")) ) then the code doesn't work. Can you tell me how this can be fixed? Thank... ;; Create a new text style and replace all styles in the drawing (defun c:cr-txtst-change ( / *error* ss eo i ff oldcmd acadDoc) (vl-load-com) (defun *error* (msg) (princ) ) ;_ end defun (setq acadApp (vlax-get-Acad-object)) (setq acadDoc (vla-get-ActiveDocument acadApp)) (setq styles (vla-get-textstyles acadDoc)) ;; Add the style named "ArialN0" (setq objStyle (vla-add styles "ArialN0")) ;; Assign fontfile "ARIALN.ttf" to the style (setq ff "C:\\Program Files\\Autodesk\\AutoCAD 2019\\Fonts\\ARIALN.ttf") (vla-put-fontfile objStyle ff) ;; Optional: Make the new style Active (vla-put-activetextstyle acadDoc objStyle) ;(princ) ;) ;; Replace all texts with the ArialN0 style ;; *************************** I'm trying to add a the possibility of choice **************** ;| (initget "All Select") (setq select (getkword "\nSelect text to change [All/Select] <Select> : ")) (if select (cond ( (= select "All") (setq SS (ssget "_X" '((0 . "*TEXT")))) ) ( (= select "Select") (setq SS (ssget "_:L")) ) ) (setq SS (ssget "_:L")) ) |; ; **************************** ;(setq ss (ssget "_X" '((0 . "*TEXT"))) i -1) ; select all texts (setq ss (ssget '((0 . "*TEXT"))) i -1) ; if you do not need to select the entire text (setq oldcmd (getvar "cmdecho")) (setvar "cmdecho" 0) (while (< (setq i (1+ i)) (sslength ss)) (setq eo (vlax-ename->vla-object (ssname ss i))) (vlax-put eo 'StyleName "ArialN0") ) (vla-EndUndoMark doc) ; Set the style to the current one (vl-cmdf "_-PURGE" "_ST" " " "_N") ; clear unused text styles (setvar "cmdecho" oldcmd) (princ) ) Edited December 30, 2024 by Nikon Quote
Tharwat Posted December 30, 2024 Posted December 30, 2024 (edited) Just remove the asterisk when checking for equality. (= select All) (= select Select) Edited December 30, 2024 by Tharwat Typo 1 Quote
Nikon Posted December 30, 2024 Author Posted December 30, 2024 (edited) On 12/30/2024 at 11:43 AM, Tharwat said: Just remove the asterisk when checking for equality. (= select All) (= select Select) Thanks, but the code doesn't work, the style is created, but the texts style doesn't change... It turns out that you need to change these lines: ( (= select "All") (setq SS (ssget "_X" '((0 . "*TEXT")))) ) ( (= select "Select") (setq SS (ssget "_:L")) ) ) (setq SS (ssget "_:L")) ) to ( (= select "All") (setq SS (ssget "_X" '((0 . "*TEXT"))) i -1) ) ( (= select "Select") (setq SS (ssget '((0 . "*TEXT"))) i -1) ) ) (setq SS setq SS (ssget '((0 . "*TEXT"))) i -1) ) so that they match the following lines: (while (< (setq i (1+ i)) (sslength ss)) (setq eo (vlax-ename->vla-object (ssname ss i))) (vlax-put eo 'StyleName "ArialN0") Now the code works! Here is the full code, if anyone is interested: ;; Create a new text style and replace all styles in the drawing (defun c:cr-txtst-sel2 ( / *error* ss eo i ff oldcmd acadDoc) (vl-load-com) (defun *error* (msg) (princ) ) ;_ end defun (setq acadApp (vlax-get-Acad-object)) (setq acadDoc (vla-get-ActiveDocument acadApp)) (setq styles (vla-get-textstyles acadDoc)) ;; Add the style named "ArialN0" (setq objStyle (vla-add styles "ArialN0")) ;; Assign fontfile "ARIALN.ttf" to the style (setq ff "C:\\Program Files\\Autodesk\\AutoCAD 2019\\Fonts\\ARIALN.ttf") (vla-put-fontfile objStyle ff) ;; Optional: Make the new style Active (vla-put-activetextstyle acadDoc objStyle) ;(princ) ;) ;; Replace All/Select texts with the ArialN0 style (initget "All Select") (setq select (getkword "\nSelect text to change [All/Select] <Select> : ")) (if select (cond ( (= select "All") (setq SS (ssget "_X" '((0 . "*TEXT"))) i -1) ) ( (= select "Select") (setq SS (ssget '((0 . "*TEXT"))) i -1) ) ) (setq SS setq SS (ssget '((0 . "*TEXT"))) i -1) ) (setq oldcmd (getvar "cmdecho")) (setvar "cmdecho" 0) (while (< (setq i (1+ i)) (sslength ss)) (setq eo (vlax-ename->vla-object (ssname ss i))) (vlax-put eo 'StyleName "ArialN0") ) (vla-EndUndoMark doc) ; Set the style to the current one (vl-cmdf "_-PURGE" "_ST" " " "_N") ; clear unused text styles (setvar "cmdecho" oldcmd) (princ) ) Edited yesterday at 07:07 AM by Nikon Quote
ronjonp Posted December 30, 2024 Posted December 30, 2024 (edited) @Nikon There were a few errors in the code you posted .. FWIW here are some modifications with comments. ;; Create a new text style and replace all styles in the drawing (defun c:cr-txtst-sel2 ;; RJP - Localize all variables (/ acaddoc eo ff i objstyle oldcmd select ss styles) (vl-load-com) ;; RJP - Check that the font can be found otherwise BOOM! Also search for the system font not tied to a CAD version (if (findfile (setq ff (strcat (getenv "WINDIR") "\\FONTS\\ARIALN.ttf"))) ;; (findfile (setq ff "C:\\Program Files\\Autodesk\\AutoCAD 2019\\Fonts\\ARIALN.ttf")) (progn (setq acaddoc (vla-get-activedocument (vlax-get-acad-object))) (setq styles (vla-get-textstyles acaddoc)) ;; Add the style named "ArialN0" (setq objstyle (vla-add styles "ArialN0")) ;; Assign fontfile "ARIALN.ttf" to the style (vla-put-fontfile objstyle ff) ;; Optional: Make the new style Active (vla-put-activetextstyle acaddoc objstyle) ;; Replace All/Select texts with the ArialN0 style (initget "All Select") (if (= "All" (setq select (getkword "\nSelect text to change [All/Select] <Select> : "))) (setq ss (ssget "_X" '((0 . "*TEXT")))) (setq ss (ssget "_:L" '((0 . "*TEXT")))) ) ;; RJP - Check for valid selection (if ss (progn (setq oldcmd (getvar "cmdecho")) (setvar "cmdecho" 0) (repeat (setq i (sslength ss)) (setq eo (vlax-ename->vla-object (ssname ss (setq i (1- i))))) ;; RJP - Check that the text can be modified (if (vlax-write-enabled-p eo) (vlax-put eo 'stylename "ArialN0") ) ) ;; RJP - This line below bombs the code? ;; (vla-endundomark doc) ; Set the style to the current one (vl-cmdf "_-PURGE" "_ST" " " "_N") ; clear unused text styles (setvar "cmdecho" oldcmd) ) ) ) (alert (strcat ff " NOT FOUND!")) ) (princ) ) Edited December 31, 2024 by ronjonp Missed setting a variable 2 Quote
BIGAL Posted December 30, 2024 Posted December 30, 2024 I don't use initget anymore rather this. (if (not AH:Butts)(load "Multi Radio buttons.lsp")) (if (= but nil)(setq but 1)) (setq ans (ah:butts but "V" '("Please Choose" "All" "All in tab" "Select objects")))) ; ans holds the button picked as an integer value (cond ((if (= ans "All")(setq ss (ssget "_X" '((0 . "*TEXT")))))) ((if (= ans "All in tab")(setq ss (ssget "_X" '((0 . "*TEXT")(cons 410 (getvar 'ctab))))))) ((if (= ans "Select objects")(setq ss (ssget "_:L" '((0 . "*TEXT")))))) ) If you don't want to use the "ans" value you can use the variable but, it is a number matching the button selected, so All would return but=1. Multi radio buttons.lsp 1 Quote
Nikon Posted December 31, 2024 Author Posted December 31, 2024 12 hours ago, ronjonp said: @Nikon There were a few errors in the code you posted .. FWIW here are some modifications with comments. @ronjonp thank you for correcting the errors and especially for the comments... My knowledge of lisp programming is very limited... Quote
Nikon Posted December 31, 2024 Author Posted December 31, 2024 7 hours ago, BIGAL said: I don't use initget anymore rather this. (if (not AH:Butts)(load "Multi Radio buttons.lsp")) (if (= but nil)(setq but 1)) (setq ans (ah:butts but "V" '("Please Choose" "All" "All in tab" "Select objects")))) ; ans holds the @BIGAL Thank you for your suggestion and Multi radio buttons.lsp. I'll try this method... Quote
Nikon Posted December 31, 2024 Author Posted December 31, 2024 13 hours ago, ronjonp said: ;; Create a new text style and replace all styles in the drawing (defun c:cr-txtst-sel2 ;; RJP - Localize all variables (/ acaddoc eo ff i objstyle oldcmd select ss styles) (vl-load-com) ;; RJP - Check that the font can be found otherwise BOOM! Also search for the system font not tied to a CAD version (if (findfile (strcat (getenv "WINDIR") "\\FONTS\\ARIALN.ttf")) ;; (findfile (setq ff "C:\\Program Files\\Autodesk\\AutoCAD 2019\\Fonts\\ARIALN.ttf")) (progn (setq acaddoc (vla-get-activedocument (vlax-get-acad-object))) (setq styles (vla-get-textstyles acaddoc)) ;; Add the style named "ArialN0" (setq objstyle (vla-add styles "ArialN0")) ;; Assign fontfile "ARIALN.ttf" to the style (vla-put-fontfile objstyle ff) ;; Optional: Make the new style Active (vla-put-activetextstyle acaddoc objstyle) ;; Replace All/Select texts with the ArialN0 style (initget "All Select") (if (= "All" (setq select (getkword "\nSelect text to change [All/Select] <Select> : "))) (setq ss (ssget "_X" '((0 . "*TEXT")))) (setq ss (ssget "_:L" '((0 . "*TEXT")))) ) ;; RJP - Check for valid selection (if ss (progn (setq oldcmd (getvar "cmdecho")) (setvar "cmdecho" 0) (repeat (setq i (sslength ss)) (setq eo (vlax-ename->vla-object (ssname ss (setq i (1- i))))) ;; RJP - Check that the text can be modified (if (vlax-write-enabled-p eo) (vlax-put eo 'stylename "ArialN0") ) ) ;; RJP - This line below bombs the code? ;; (vla-endundomark doc) ; Set the style to the current one (vl-cmdf "_-PURGE" "_ST" " " "_N") ; clear unused text styles (setvar "cmdecho" oldcmd) ) ) ) (alert (strcat ff " NOT FOUND!")) ) (princ) ) For some reason, this code doesn't work. ; error: ActiveX Server returned an error: The parameter is required Quote
ronjonp Posted December 31, 2024 Posted December 31, 2024 5 hours ago, Nikon said: For some reason, this code doesn't work. ; error: ActiveX Server returned an error: The parameter is required Try the code above again .. I missed setting the 'ff' variable. 1 Quote
Nikon Posted December 31, 2024 Author Posted December 31, 2024 (edited) 1 hour ago, ronjonp said: Try the code above again .. I missed setting the 'ff' variable. @ronjonp Thank you very much, now the code works perfectly! Creative success in the new year! Edited December 31, 2024 by Nikon Quote
ronjonp Posted December 31, 2024 Posted December 31, 2024 55 minutes ago, Nikon said: @ronjonp Thank you very much, now the code works perfectly! Creative success in the new year! 1 Quote
Recommended Posts
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.