Visual LISP, AutoLISP and General Customization

Reply
Mentor
richie.hodgson
Posts: 208
Registered: ‎11-05-2008
Message 1 of 4 (174 Views)

Show diference in selected text

174 Views, 3 Replies
01-17-2013 06:04 PM

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

Richie
Mentor
devitg
Posts: 1,692
Registered: ‎03-14-2004
Message 2 of 4 (168 Views)

Re: Show diference in selected text

01-17-2013 06:48 PM in reply to: richie.hodgson
(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)
)

 

*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 3 of 4 (146 Views)

Re: Show diference in selected text

01-17-2013 09:55 PM in reply to: richie.hodgson

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

 

Mentor
richie.hodgson
Posts: 208
Registered: ‎11-05-2008
Message 4 of 4 (100 Views)

Re: Show diference in selected text

01-28-2013 12:45 PM in reply to: richie.hodgson

Thanks for that, works a treat. Nice easy fix. Have been on annual leave so sorry for delay in responding

Richie

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community