Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

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

Show diference in selected text

193 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,700
Registered: ‎03-14-2004
Message 2 of 4 (187 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,459
Registered: ‎11-24-2009
Message 3 of 4 (165 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: 211
Registered: ‎11-05-2008
Message 4 of 4 (119 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
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 or visit the Installation and Licensing Forum to get help installing your software.