Nikon Posted Sunday at 09:47 AM Posted Sunday at 09:47 AM Good day everyone! After editing the text, its color changes, but to exit the command, you need to press RMB or enter or Esc twice. Is it possible to complete the execution of the command with the right mouse button in one click? ;; If the current color is not equal to 136, then change it to 136. ;; If the current color is 136, then change it to 230. (defun c:TEcolor136_230 (/ error oldcmdecho sel e type obj res currentColor) (vl-load-com) (defun error (msg) (if oldcmdecho (setvar "CMDECHO" oldcmdecho)) (if (and msg (not (wcmatch (strcase msg) "BREAK,CANCEL,EXIT"))) (princ (strcat " Error: " msg)) ) (princ) ) (setq oldcmdecho (getvar "CMDECHO")) (setvar "CMDECHO" 0) (while (setq sel (entsel " Select TEXT/MTEXT to edit (Enter — exit): ")) (setq e (car sel) type (strcase (cdr (assoc 0 (entget e)))) ) (if (wcmatch type "TEXT,MTEXT") (progn (setq obj (vlax-ename->vla-object e)) ;; get the current color (setq currentColor (vl-catch-all-apply 'vlax-get-property (list obj 'Color)) ) ;; Error handling on receipt (if (vl-catch-all-error-p currentColor) (setq currentColor 0) ) ;; Opening the text editor (setq res (vl-catch-all-apply 'vl-cmdf (list "_.textedit" e)) ) (if (vl-catch-all-error-p res) (princ " Editing canceled.") ;; After editing, we change the color (progn (if (= currentColor 136) ;; If it's 136, change it to 230. (if (vl-catch-all-error-p (vl-catch-all-apply 'vlax-put-property (list obj 'Color 230)) ) (princ " Couldn't change color to 230.") (princ " The color has been changed to 230.") ) ) (if (/= currentColor 136) ;; If it's not 136, change it to 136. (if (vl-catch-all-error-p (vl-catch-all-apply 'vlax-put-property (list obj 'Color 136)) ) (princ " Couldn't change the color to 136.") (princ " The color has been changed to 136.") ) ) (princ " Editing completed.") ) ) ) (princ " It's not an object TEXT/MTEXT.") ) ) (setvar "CMDECHO" oldcmdecho) (princ) ) Quote
GLAVCVS Posted Sunday at 10:20 AM Posted Sunday at 10:20 AM (edited) Do you only need to change the color or also edit the text? Edited Sunday at 10:21 AM by GLAVCVS Quote
Nikon Posted Sunday at 12:28 PM Author Posted Sunday at 12:28 PM 2 hours ago, GLAVCVS said: Do you only need to change the color or also edit the text? I need to edit the text and change the color. Quote
BIGAL Posted Sunday at 11:24 PM Posted Sunday at 11:24 PM (edited) Why not check the color 1st change the color then edit it ? Also you can shorten the get put property. Must be a vl object. (setq colorobj (vlax-get obj 'color)) (vlax-put obj 'color 230) Maybe this also ;; If it's 136, change it to 230. (if (= currentColor 136) (vlax-put obj 'color 230) (vlax-put obj 'color 130) ) To select only *text you can use a ssget (while (setq ss (ssget '(( 0 . "*TEXT")))) (setq e (ssname ss 0)) (setq obj (vlax-ename->vla-object e)) Have a look at Lee-mac SSGET functions look at the E: option. Edited Sunday at 11:25 PM by BIGAL 1 Quote
GLAVCVS Posted yesterday at 09:27 AM Posted yesterday at 09:27 AM (edited) 23 hours ago, Nikon said: Good day everyone! After editing the text, its color changes, but to exit the command, you need to press RMB or enter or Esc twice. Is it possible to complete the execution of the command with the right mouse button in one click? ;; If the current color is not equal to 136, then change it to 136. ;; If the current color is 136, then change it to 230. (defun c:TEcolor136_230 (/ error oldcmdecho sel e type obj res currentColor) (vl-load-com) (defun error (msg) (if oldcmdecho (setvar "CMDECHO" oldcmdecho)) (if (and msg (not (wcmatch (strcase msg) "BREAK,CANCEL,EXIT"))) (princ (strcat " Error: " msg)) ) (princ) ) (setq oldcmdecho (getvar "CMDECHO")) (setvar "CMDECHO" 0) (while (setq sel (entsel " Select TEXT/MTEXT to edit (Enter — exit): ")) (setq e (car sel) type (strcase (cdr (assoc 0 (entget e)))) ) (if (wcmatch type "TEXT,MTEXT") (progn (setq obj (vlax-ename->vla-object e)) ;; get the current color (setq currentColor (vl-catch-all-apply 'vlax-get-property (list obj 'Color)) ) ;; Error handling on receipt (if (vl-catch-all-error-p currentColor) (setq currentColor 0) ) ;; Opening the text editor (setq res (vl-catch-all-apply 'vl-cmdf (list "_.textedit" e)) ) (if (vl-catch-all-error-p res) (princ " Editing canceled.") ;; After editing, we change the color (progn (if (= currentColor 136) ;; If it's 136, change it to 230. (if (vl-catch-all-error-p (vl-catch-all-apply 'vlax-put-property (list obj 'Color 230)) ) (princ " Couldn't change color to 230.") (princ " The color has been changed to 230.") ) ) (if (/= currentColor 136) ;; If it's not 136, change it to 136. (if (vl-catch-all-error-p (vl-catch-all-apply 'vlax-put-property (list obj 'Color 136)) ) (princ " Couldn't change the color to 136.") (princ " The color has been changed to 136.") ) ) (princ " Editing completed.") ) ) ) (princ " It's not an object TEXT/MTEXT.") ) ) (setvar "CMDECHO" oldcmdecho) (princ) ) I think you need one ENTER to exit from 'textedit' and another one to exit from the while loop. I think It’s not possible to solve everything with a right click. The only option that comes close to what you’re asking for is to remove the while loop, so that the command ends after editing each text. But this will force you to press right click to repeat the command. The only option that would allow what you’re describing is to edit the text content with getstring instead of textedit. But I don’t know if you’re willing to do that. Edited yesterday at 09:28 AM by GLAVCVS 1 Quote
Nikon Posted yesterday at 09:49 AM Author Posted yesterday at 09:49 AM 20 minutes ago, GLAVCVS said: I think you need one ENTER to exit from 'textedit' and another one to exit from the while loop. I think It’s not possible to solve everything with a right click. The only option that comes close to what you’re asking for is to remove the while loop, so that the command ends after editing each text. But this will force you to press right click to repeat the command. The only option that would allow what you’re describing is to edit the text content with getstring instead of textedit. That's fine with me... Quote
GLAVCVS Posted yesterday at 10:36 AM Posted yesterday at 10:36 AM There's another option: to respect the call to 'textedit' and exit it by clicking the mouse over the empty background. This is the option applied in the attached code. (defun c:TEcolor136_230 (/ error oldcmdecho sel e typo obj res currentColor para) (vl-load-com) (defun error (msg) (if oldcmdecho (setvar "CMDECHO" oldcmdecho) ) (if (and msg (not (wcmatch (strcase msg) "BREAK,CANCEL,EXIT"))) (princ (strcat "Error: " msg)) ) (princ) ) (setq oldcmdecho (getvar "CMDECHO")) (setvar "CMDECHO" 0) ;;; (while (setq sel (entsel "\nSelect TEXT/MTEXT to edit (Enter — exit): ")) (setq sel (entsel "\nSelect TEXT/MTEXT to edit (Enter — exit): ") e (car sel) typo (strcase (cdr (assoc 0 (entget e)))) ) (if (wcmatch typo "TEXT,MTEXT") (progn (setq obj (vlax-ename->vla-object e)) ;; get the current color (setq currentColor (vl-catch-all-apply 'vlax-get-property (list obj 'Color)) ) ;; Error handling on receipt (if (vl-catch-all-error-p currentColor) (setq currentColor 0) ) ;; Opening the text editor (getstring) (setq res (vl-catch-all-apply 'vl-cmdf (list "_.textedit" e "")) ) ;;; (if (/= (setq res (getstring (strcat "\nEdit text <" (cdr (assoc 1 (entget e))) ">: "))) "") ;;; (entmod (subst (cons 1 res) (assoc 1 (entget e)) (entget e))) ;;; ) (if (vl-catch-all-error-p res) (princ "Editing canceled.") ;; After editing, we change the color (progn (if (= currentColor 136) ;; If it's 136, change it to 230. (if (vl-catch-all-error-p (vl-catch-all-apply 'vlax-put-property (list obj 'Color 230) ) ) (princ "Couldn't change color to 230.") (princ "The color has been changed to 230.") ) ) (if (/= currentColor 136) ;; If it's not 136, change it to 136. (if (vl-catch-all-error-p (vl-catch-all-apply 'vlax-put-property (list obj 'Color 136) ) ) (princ "Couldn't change the color to 136.") (princ "The color has been changed to 136.") ) ) (princ "Editing completed.") ) ) ) (princ "It's not an object TEXT/MTEXT.") ) ;;; ) (setvar "CMDECHO" oldcmdecho) (princ) ) 1 Quote
GLAVCVS Posted yesterday at 10:38 AM Posted yesterday at 10:38 AM I hope the 'textedit' options in your version of AutoCAD aren't a problem. 1 Quote
GLAVCVS Posted yesterday at 10:50 AM Posted yesterday at 10:50 AM If you don't want the command to end after editing the text, you can keep the "while" loop, as shown in this other code. The operation will be the same except that to exit the command, you'll need an additional "right click." (defun c:TEcolor136_230 (/ error oldcmdecho sel e typo obj res currentColor para) (vl-load-com) (defun error (msg) (if oldcmdecho (setvar "CMDECHO" oldcmdecho) ) (if (and msg (not (wcmatch (strcase msg) "BREAK,CANCEL,EXIT"))) (princ (strcat "Error: " msg)) ) (princ) ) (setq oldcmdecho (getvar "CMDECHO")) (setvar "CMDECHO" 0) (while (setq sel (entsel "\nSelect TEXT/MTEXT to edit (Enter — exit): ")) (setq ;sel (entsel "\nSelect TEXT/MTEXT to edit (Enter — exit): ") e (car sel) typo (strcase (cdr (assoc 0 (entget e)))) ) (if (wcmatch typo "TEXT,MTEXT") (progn (setq obj (vlax-ename->vla-object e)) ;; get the current color (setq currentColor (vl-catch-all-apply 'vlax-get-property (list obj 'Color)) ) ;; Error handling on receipt (if (vl-catch-all-error-p currentColor) (setq currentColor 0) ) ;; Opening the text editor (getstring) (setq res (vl-catch-all-apply 'vl-cmdf (list "_.textedit" e "")) ) ;;; (if (/= (setq res (getstring (strcat "\nEdit text <" (cdr (assoc 1 (entget e))) ">: "))) "") ;;; (entmod (subst (cons 1 res) (assoc 1 (entget e)) (entget e))) ;;; ) (if (vl-catch-all-error-p res) (princ "Editing canceled.") ;; After editing, we change the color (progn (if (= currentColor 136) ;; If it's 136, change it to 230. (if (vl-catch-all-error-p (vl-catch-all-apply 'vlax-put-property (list obj 'Color 230) ) ) (princ "Couldn't change color to 230.") (princ "The color has been changed to 230.") ) ) (if (/= currentColor 136) ;; If it's not 136, change it to 136. (if (vl-catch-all-error-p (vl-catch-all-apply 'vlax-put-property (list obj 'Color 136) ) ) (princ "Couldn't change the color to 136.") (princ "The color has been changed to 136.") ) ) (princ "Editing completed.") ) ) ) (princ "It's not an object TEXT/MTEXT.") ) ) (setvar "CMDECHO" oldcmdecho) (princ) ) 1 Quote
Nikon Posted yesterday at 11:03 AM Author Posted yesterday at 11:03 AM 27 minutes ago, GLAVCVS said: here's another option: to respect the call to 'textedit' and exit it by clicking the mouse over the empty background. This is the option applied in the attached code. @GLAVCVS thank you very much for the 2 options, I like both options, but the first option suits me better. Quote
thekiki Posted yesterday at 03:24 PM Posted yesterday at 03:24 PM Hi all, Is there a possibility to select multiple text at once. Thanks for your answer. Quote
BIGAL Posted 17 hours ago Posted 17 hours ago @thekiki what did you have in mind to do with the selected text ? Quote
thekiki Posted 11 hours ago Posted 11 hours ago Hi Bigal, With the GLAVCVS's lisp (TEcolor136_230), i can only select text one by one. I would like to select several text at the same time in the selection. Thanks for your help. Quote
GLAVCVS Posted 5 hours ago Posted 5 hours ago 5 hours ago, thekiki said: Hi Bigal, With the GLAVCVS's lisp (TEcolor136_230), i can only select text one by one. I would like to select several text at the same time in the selection. Thanks for your help. Do you want to edit the content of a text and apply the same modification to the rest of the selected texts? Quote
thekiki Posted 5 hours ago Posted 5 hours ago This is the first possibilitie. The second possibilitie that i only want to select multiple texts (not edited) and if: -the current color is not equal to 136, then change it to 136. -the current color is 136, then change it to 230. thanks for your help! Quote
GLAVCVS Posted 1 hour ago Posted 1 hour ago Some Like This (defun c:TEcolor136_230 (/ error oldcmdecho sel e typo obj res currentColor n ch? tx) (vl-load-com) (defun error (msg) (if oldcmdecho (setvar "CMDECHO" oldcmdecho) ) (if (and msg (not (wcmatch (strcase msg) "BREAK,CANCEL,EXIT"))) (princ (strcat "Error: " msg)) ) (princ) ) (setq oldcmdecho (getvar "CMDECHO")) (setvar "CMDECHO" 0) (setvar "NOMUTT" 1) ;;; (while (setq sel (entsel "\nSelect TEXT/MTEXT to edit (Enter — exit): ")) (princ "\nSelect TEXTs/MTEXTs to edit (Enter — exit): ") (setq sel (ssget '((0 . "*TEXT"))) e (ssname sel 0) ;;; typo (strcase (cdr (assoc 0 (entget e)))) ) (if sel (progn (setq obj (vlax-ename->vla-object e) tx (cdr (assoc 1 (entget e)));(vla-getTextString obj) ) ;; get the current color (setq currentColor (vl-catch-all-apply 'vlax-get-property (list obj 'Color))) ;; Error handling on receipt (if (vl-catch-all-error-p currentColor) (setq currentColor 0) ) (princ "\rEdit text and left click on empty screen for continue") ;; Opening the text editor (getstring) (setq n -1 res (vl-catch-all-apply 'vl-cmdf (list "_.textedit" e "")) ch? (/= tx (setq tx (cdr (assoc 1 (entget e))))) ) (if (vl-catch-all-error-p res) (princ "\nEditing canceled.") (while (setq e (ssname sel (setq n (1+ n)))) (setq obj (vlax-ename->vla-object e)) (if (and ch? (> n 0)) (entmod (subst (cons 1 tx) (assoc 1 (entget e)) (entget e))) ) ;; After editing, we change the color (if (= currentColor 136) ;; If it's 136, change it to 230. (if (vl-catch-all-error-p (vl-catch-all-apply 'vlax-put-property (list obj 'Color 230) ) ) (princ "\nCouldn't change color to 230.") (princ "\nThe color has been changed to 230.") ) ) (if (/= currentColor 136) ;; If it's not 136, change it to 136. (if (vl-catch-all-error-p (vl-catch-all-apply 'vlax-put-property (list obj 'Color 136) ) ) (princ "\nCouldn't change the color to 136.") (princ "\nThe color has been changed to 136.") ) ) ) ) (if obj (princ "\nEditing completed.")) ) (princ "\nIt's not an object TEXT/MTEXT.") ) (setvar "CMDECHO" oldcmdecho) (setvar "NOMUTT" 0) (princ) ) 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.