I have a little routine to add two selected numerical texts together and show the result at a selected position. I am using the entsel method to select them. I would like a way to highlight the selected text temporarily. Is this possible. The routine is as follows.
(defun c:T+ ( / Txt1 Txt2 Txt3 Pkt )
;Adds second selected number to first
(setvar "dimzin" 3)
(setq curlay (getvar "clayer"))
(setq curcol (getvar "cecolor"))
(setq curlin (getvar "celtype"))
(setq ds (getvar "dimscale"))
(setq oldos (getvar "osmode"))
(setq Txt1 (entsel "Select first text : " ) )
(setq Txt2 (entsel "Select second text : " ) )
(setq Txt3
(strcat
(rtos (+ (atof (cdr (assoc 1 (entget (car Txt1 ))))) (atof (cdr (assoc 1 (entget (car Txt2 ))))) ) 2 3 )
)
)
(setvar "osmode" 32)
(setq cx (* ds -1))
(setq cy (* ds 1.5))
(setq Pkt (getpoint "Where to place result ? : ") )
(setq ptx (car Pkt))
(setq ptx (+ cx ptx))
(setq pty (cadr Pkt))
(setq pty (+ cy pty ))
(setq Pkt (list ptx pty 0))
(setvar "textstyle" "s35")
(setvar "cecolor" "cyan")
(setvar "celtype" "continuous")
(setvar "osmode" 0)
(command "._text" Pkt "0" Txt3 )
(setvar "osmode" oldos)
(setvar "clayer" curlay)
(setvar "cecolor" curcol)
(setvar "celtype" curlin)
(princ)
)
(defun c:T+ ( / Txt1 Txt2 Txt3 Pkt ) ;Adds second selected number to first (setvar "dimzin" 3) (setq curlay (getvar "clayer")) (setq curcol (getvar "cecolor")) (setq curlin (getvar "celtype")) (setq ds (getvar "dimscale")) (setq oldos (getvar "osmode")) (setq Txt1 (entsel "Select first text : " ) ) (redraw (car Txt1) 3);_ highligth (setq Txt2 (entsel "Select second text : " ) ) (redraw (car Txt2) 3) (setq Txt3 (strcat (rtos (+ (atof (cdr (assoc 1 (entget (car Txt1 ))))) (atof (cdr (assoc 1 (entget (car Txt2 ))))) ) 2 3 ) ) ) (setvar "osmode" 32) (setq cx (* ds -1)) (setq cy (* ds 1.5)) (setq Pkt (getpoint "Where to place result ? : ") ) (setq ptx (car Pkt)) (setq ptx (+ cx ptx)) (setq pty (cadr Pkt)) (setq pty (+ cy pty )) (setq Pkt (list ptx pty 0)) ;(setvar "textstyle" "s35") (setvar "cecolor" "cyan") (setvar "celtype" "continuous") (setvar "osmode" 0) (command "._text" Pkt "" "0" Txt3 ); _ added te textsize (redraw (car Txt1) 4);_ de highligth (redraw (car Txt2) 4) (setvar "osmode" oldos) (setvar "clayer" curlay) (setvar "cecolor" curcol) (setvar "celtype" curlin) (princ) )
@richie_hodgson wrote:I have a little routine to add two selected numerical texts together and show the result at a selected position....
Suggestion:
Use ssget for selection, that way you are not limited to 2 objects plus you can use a filter.
(defun c:demo (/ Txt3 numstr i str) (if (setq Txt3 0 numstr (ssget '((0 . "TEXT")(1 . "#*")))) (repeat (setq i (sslength numstr)) (setq str (read (cdr (assoc 1 (entget (ssname numstr (setq i (1- i))))))) Txt3 (+ str Txt3 ))) ) (vl-princ-to-string Txt3) )
HTH
Thanks for that, works a treat. Nice easy fix. Have been on annual leave so sorry for delay in responding