Jump to content

Recommended Posts

Posted

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)
)

 

Posted (edited)

Do you only need to change the color or also edit the text?

Edited by GLAVCVS
Posted
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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...