Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Computer Aided Design - CAD > Autocad > Re: lisp progra...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 8 Topic 3414 of 3502
Post > Topic >>

Re: lisp program to add text values-fractions etc??

by strawberry <zac.carey@[EMAIL PROTECTED] > Apr 24, 2008 at 11:58 PM

On Apr 24, 11:34 pm, strawberry <zac.ca...@[EMAIL PROTECTED]
> wrote:
> On Apr 24, 3:27 pm, strawberry <zac.ca...@[EMAIL PROTECTED]
> wrote:
>
>
>
> > On 24 Apr, 14:45, strawberry <zac.ca...@[EMAIL PROTECTED]
> wrote:
>
> > > On 23 Apr, 22:15, "R. Hamm" <rallo...@[EMAIL PROTECTED]
> wrote:
>
> > > > anyone know where I can find a lsp program where I can select
existing
> > > > text in the drawing,
> > > > eg.
> > > > 12'-2 1/2"
> > > > 3 1/2"
> > > > 13' 4 3/8"
> > > > and it adds it all up for me?
> > > > I searched with no luck yet.
> > > > Thanks in advance!
> > > > Ramey
>
> > > Hmm, are these text objects or something else, e.g. dims?
>
> > Anyway, I don't have a complete solution, however, this routine from
> > Cadalyst should get you started:
>
> > ; ----- ADDNUM.LSP -----
> > ; CADalyst Oct. 1991, p. 84
> > ; TIP #703
>
> > ; Adds numbers by pick.
>
> > (defun C:ADDNUM (/ ENT CT ANX SNUM SLEN E EE X)
> > (prompt "\nPick numbers to add: (CANNOT HAVE COMMAS) ")
> > (setq ENT (ssget)) ; pick text
> > (setq CT 0 ; initialize counts
> > ANX 0)
> > (setq SNUM (ssname ENT CT)) ; get first piece of text
> > (setq SLEN (sslength ENT)) ; get number of pieces
> > (while (<= (1+ CT) SLEN) ; loop through selection set
> > (setq SNUM (ssname ENT CT) ; get next number's ENAME
> > E (entget SNUM) ; get entity data
> > EE (cdr (assoc 1 E)) ; get text value
> > X (atof EE)) ; convert string to real
> > (setq ANX (+ ANX X) ; add number to base
> > CT (1+ CT)) ; increment counter
> > )
> > (princ "\nTotal = ")(princ (rtos ANX 2 4)) ; print in decimal form.
> > (princ)
> > )
>
> > and the distof function can convert architectural fractions to real
> > numbers:
>
> > eg:
> > (distof "1'-5 1/2\"" 4)
> > 17.5
>
> > Put them together, stir it around a bit and hey presto!?! Anyway, let
> > us know how you get on.
>
> > Oh, and this function from Bill Kramer's AutoCADet's Guide to Visual
> > Lisp converts distance by testing all unit types (apparently)
>
> > (DEFUN CONVERTDISTANCE (S / LU RES TMP)
> > (SETQ LU 1)
> > (REPEAT 5 ;Five types to test
> > (SETQ TMP (DISTOF S LU)
> > LU (1+ LU))
> > (IF TMP (SETQ RES TMP)))
> > RES)
>
> I tried this earlier but it didn't seem to work. I tried it again just
> now and it worked perfectly, so go figure!?!
>
> ; ----- ADDNUMX.LSP -----
> ; CADalyst Oct. 1991, p. 84 with a tiny adaptation from strawberry
> ; TIP #703
>
> ; Adds numbers by pick.
>
> (defun C:ADDNUMX (/ ENT CT ANX SNUM SLEN E EE X)
> (prompt "\nPick numbers to add: (CANNOT HAVE COMMAS) ")
> (setq ENT (ssget)) ; pick text
> (setq CT 0 ; initialize counts
> ANX 0)
> (setq SNUM (ssname ENT CT)) ; get first piece of text
> (setq SLEN (sslength ENT)) ; get number of pieces
> (while (<= (1+ CT) SLEN) ; loop through selection set
> (setq SNUM (ssname ENT CT) ; get next number's ENAME
> E (entget SNUM) ; get entity data
> EE (cdr (assoc 1 E)) ; get text value
> X (distof EE 4)) ; convert string to real
> (setq ANX (+ ANX X) ; add number to base
> CT (1+ CT)) ; increment counter
> )
> (princ "\nTotal = ")(princ (rtos ANX 2 4)) ; print in decimal form.
> (princ)
> )

So, I guess this is a more thorough solution:

; ----- ADDNUMX.LSP -----
; CADalyst Oct. 1991, p. 84 with a tiny adaptation from strawberry
; TIP #703

;A 'distance conversion' function (from Bill Kramer)
(DEFUN CONVERTDISTANCE (S / LU RES TMP)
(SETQ LU 1)
(REPEAT 5 ;Five types to test
(SETQ TMP (DISTOF S LU)
LU (1+ LU))
(IF TMP (SETQ RES TMP)))
RES)

; Adds numbers by pick.

(defun C:ADDNUMX (/ ENT CT ANX SNUM SLEN E EE X)
(prompt "\nPick numbers to add: (CANNOT HAVE COMMAS) ")
(setq ENT (ssget)) ; pick text
(setq CT 0 ; initialize counts
ANX 0)
(setq SNUM (ssname ENT CT)) ; get first piece of text
(setq SLEN (sslength ENT)) ; get number of pieces
(while (<= (1+ CT) SLEN) ; loop through selection set
(setq SNUM (ssname ENT CT) ; get next number's ENAME
E (entget SNUM) ; get entity data
EE (cdr (assoc 1 E)) ; get text value
X (CONVERTDISTANCE (EE))) ; convert string to real
(setq ANX (+ ANX X) ; add number to base
CT (1+ CT)) ; increment counter
)
(princ "\nTotal = ")(princ (rtos ANX 2 4)) ; print in decimal form.
(princ)
)
 




 8 Posts in Topic:
lisp program to add text values-fractions etc??
"R. Hamm" <r  2008-04-23 14:15:35 
Re: lisp program to add text values-fractions etc??
strawberry <zac.carey@  2008-04-24 06:45:37 
Re: lisp program to add text values-fractions etc??
strawberry <zac.carey@  2008-04-24 07:27:28 
Re: lisp program to add text values-fractions etc??
strawberry <zac.carey@  2008-04-24 15:34:30 
Re: lisp program to add text values-fractions etc??
strawberry <zac.carey@  2008-04-24 23:58:40 
Re: lisp program to add text values-fractions etc??
"YDOD" <walk  2008-04-25 14:17:44 
Re: lisp program to add text values-fractions etc??
"R. Hamm" <r  2008-04-28 16:02:21 
Re: lisp program to add text values-fractions etc??
strawberry <zac.carey@  2008-04-29 02:19:34 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Sep 6 19:48:30 CDT 2008.