Help Needed
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
Help Needed

 
Post new topic   Reply to topic    CADForums.net Forum Index -> Customization
Author Message
Kenny Poong
Guest





Posted: Wed Jan 12, 2005 10:03 am    Post subject: Help Needed Reply with quote

Hi NG,

I use the lisp below to help me to add up the selected numbers.

I would like to have comma for the total. ( 1,000 instead of 1000 )

Can some one help me to correct it ?

TIA.


(defun C:Add (/ p l n e as s tot)
(setq tot 0 p (ssget)) ; Select objects
(if p (progn ; If any objects selected
(setq l 0 n (sslength p))
(while (< l n) ; For each selected
object...
(if (= "TEXT" ; Look for TEXT entity type
(group 0)
(cdr (assoc 0 (setq e (entget (ssname p l)))))
)
(progn
(setq s (stripit "," (cdr (setq as (assoc 1 e)))))
(setq tot (+ (atof s) tot))
)
)
(setq l (1+ l))
)
)
)
(princ (strcat "\nTotal: " (rtos tot 2 4))) ; second 4 sets number of
decimal places
(setq at (car (entsel "\. Select entity to change to new total or
enter\n")))
(if at
(progn
(setq enl (entget at))
(setq e (subst (cons 1 (rtos tot 2 4)) (assoc 1 enl) enl))
(entmod e)
(princ)
)
)
)
(defun stripit (schar sstring / ptr ctr fnd ts)
(setq ptr (strlen sstring)
ctr 0
fnd nil
ts ""
)
(repeat ptr
(setq ctr (+ 1 ctr))
(setq fnd (= (substr sstring ctr 1) schar))
(if (not fnd)
(setq ts (strcat ts (substr sstring ctr 1)))
)
)
)

Back to top
Adesu
Guest





Posted: Wed Jan 12, 2005 10:03 am    Post subject: Re: Help Needed Reply with quote

Sorry Kenny,I've wrong interpreted!

Adesu <mteybid@yuasabattery.co.id> wrote in message
news:41e4db49_2@newsprd01...
Quote:
Hi Kenny,

; error: no function definition: GROUP

(if (= "TEXT" (group 0) (cdr (assoc 0 (setq e (entget (ssname p l)))))))

it should

(if (= "TEXT" (cdr (assoc 0 (setq e (entget (ssname p l))))))........


Kenny Poong <kennypmw@time.net.my> wrote in message
news:41e4d79f_1@newsprd01...
Hi NG,

I use the lisp below to help me to add up the selected numbers.

I would like to have comma for the total. ( 1,000 instead of 1000 )

Can some one help me to correct it ?

TIA.


(defun C:Add (/ p l n e as s tot)
(setq tot 0 p (ssget)) ; Select objects
(if p (progn ; If any objects
selected
(setq l 0 n (sslength p))
(while (< l n) ; For each selected
object...
(if (= "TEXT" ; Look for TEXT entity
type
(group 0)
(cdr (assoc 0 (setq e (entget (ssname p l)))))
)
(progn
(setq s (stripit "," (cdr (setq as (assoc 1 e)))))
(setq tot (+ (atof s) tot))
)
)
(setq l (1+ l))
)
)
)
(princ (strcat "\nTotal: " (rtos tot 2 4))) ; second 4 sets number
of
decimal places
(setq at (car (entsel "\. Select entity to change to new total or
enter\n")))
(if at
(progn
(setq enl (entget at))
(setq e (subst (cons 1 (rtos tot 2 4)) (assoc 1 enl) enl))
(entmod e)
(princ)
)
)
)
(defun stripit (schar sstring / ptr ctr fnd ts)
(setq ptr (strlen sstring)
ctr 0
fnd nil
ts ""
)
(repeat ptr
(setq ctr (+ 1 ctr))
(setq fnd (= (substr sstring ctr 1) schar))
(if (not fnd)
(setq ts (strcat ts (substr sstring ctr 1)))
)
)
)



Back to top
Adesu
Guest





Posted: Wed Jan 12, 2005 10:03 am    Post subject: Re: Help Needed Reply with quote

Hi Kenny,

; error: no function definition: GROUP

(if (= "TEXT" (group 0) (cdr (assoc 0 (setq e (entget (ssname p l)))))))

it should

(if (= "TEXT" (cdr (assoc 0 (setq e (entget (ssname p l))))))........


Kenny Poong <kennypmw@time.net.my> wrote in message
news:41e4d79f_1@newsprd01...
Quote:
Hi NG,

I use the lisp below to help me to add up the selected numbers.

I would like to have comma for the total. ( 1,000 instead of 1000 )

Can some one help me to correct it ?

TIA.


(defun C:Add (/ p l n e as s tot)
(setq tot 0 p (ssget)) ; Select objects
(if p (progn ; If any objects selected
(setq l 0 n (sslength p))
(while (< l n) ; For each selected
object...
(if (= "TEXT" ; Look for TEXT entity
type
(group 0)
(cdr (assoc 0 (setq e (entget (ssname p l)))))
)
(progn
(setq s (stripit "," (cdr (setq as (assoc 1 e)))))
(setq tot (+ (atof s) tot))
)
)
(setq l (1+ l))
)
)
)
(princ (strcat "\nTotal: " (rtos tot 2 4))) ; second 4 sets number of
decimal places
(setq at (car (entsel "\. Select entity to change to new total or
enter\n")))
(if at
(progn
(setq enl (entget at))
(setq e (subst (cons 1 (rtos tot 2 4)) (assoc 1 enl) enl))
(entmod e)
(princ)
)
)
)
(defun stripit (schar sstring / ptr ctr fnd ts)
(setq ptr (strlen sstring)
ctr 0
fnd nil
ts ""
)
(repeat ptr
(setq ctr (+ 1 ctr))
(setq fnd (= (substr sstring ctr 1) schar))
(if (not fnd)
(setq ts (strcat ts (substr sstring ctr 1)))
)
)
)



Back to top
Adesu
Guest





Posted: Wed Jan 12, 2005 10:03 am    Post subject: Re: Help Needed Reply with quote

Hi Kenny, check my code may be I can help you

ac is stand for add comma
; Design by Ade Suharna <mteybid@yuasabattery.co.id>
; 12 January 2005
; Program no. 162/01/2005
; Edit by
(defun c:ac (/ ent info1 ltex opt com ntex 0tex revtex ed)
(while
(setq ent (entget (car (entsel "\nCLICK TEXT FOR EDIT:")))
info1 (cdr (assoc 1 ent))
ltex (strlen info1)
opt (fix(getreal "\nCOUNT NUMBER TO ADD COMMA: "))
com ","
ntex (substr info1 1 opt)
0tex (substr info1 (1+ opt)(1- ltex))
revtex (strcat ntex com 0tex)
ed (subst (cons 1 revtex)(assoc 1 ent) ent))
(entmod ed)
)
(princ)
)

Kenny Poong <kennypmw@time.net.my> wrote in message
news:41e4d79f_1@newsprd01...
Quote:
Hi NG,

I use the lisp below to help me to add up the selected numbers.

I would like to have comma for the total. ( 1,000 instead of 1000 )

Can some one help me to correct it ?

TIA.


(defun C:Add (/ p l n e as s tot)
(setq tot 0 p (ssget)) ; Select objects
(if p (progn ; If any objects selected
(setq l 0 n (sslength p))
(while (< l n) ; For each selected
object...
(if (= "TEXT" ; Look for TEXT entity
type
(group 0)
(cdr (assoc 0 (setq e (entget (ssname p l)))))
)
(progn
(setq s (stripit "," (cdr (setq as (assoc 1 e)))))
(setq tot (+ (atof s) tot))
)
)
(setq l (1+ l))
)
)
)
(princ (strcat "\nTotal: " (rtos tot 2 4))) ; second 4 sets number of
decimal places
(setq at (car (entsel "\. Select entity to change to new total or
enter\n")))
(if at
(progn
(setq enl (entget at))
(setq e (subst (cons 1 (rtos tot 2 4)) (assoc 1 enl) enl))
(entmod e)
(princ)
)
)
)
(defun stripit (schar sstring / ptr ctr fnd ts)
(setq ptr (strlen sstring)
ctr 0
fnd nil
ts ""
)
(repeat ptr
(setq ctr (+ 1 ctr))
(setq fnd (= (substr sstring ctr 1) schar))
(if (not fnd)
(setq ts (strcat ts (substr sstring ctr 1)))
)
)
)

Back to top
Josh
Guest





Posted: Wed Jan 12, 2005 8:14 pm    Post subject: Re: Help Needed Reply with quote

Here is a crude function I wrote years ago when I was very new to Lisp and I
haven't touched it since (it works fine for the rare occasion I use
it...hmmm, I should rewrite it soon)

;;;formats an INTEGER into the "X,XXX,XXX" format (thousands) as a string
;;; 1234 returns "1,234"
;;; 1234.56 returns "1,234"
;;; "1234.56" returns "1,234.56"
;;;if you want a REAL returned you must format <comma_a> as a STRING with
RTOS
(defun commatize (comma_a / comma_go comma_b
comma_c comma_d comma_e comma_f
cnt temp_beg temp_end
)
(setq comma_go t
temp_beg ""
temp_end ""
)
(cond
((or (= (type comma_a) 'int) (= (type comma_a) 'real))
(setq
comma_b (fix comma_a)
comma_d (itoa comma_b)
comma_e (strlen comma_d)
)
)
((= (type comma_a) 'str)
(progn
(setq cnt 1)
(if (wcmatch comma_a "*`.*")
(progn
(while (/= (substr comma_a cnt 1) ".")
(setq
temp_beg (strcat temp_beg (substr comma_a cnt 1))
cnt (1+ cnt)
temp_end (substr comma_a cnt)
)
)
(setq comma_a temp_beg)
)
)
(setq
comma_e (strlen comma_a)
comma_d comma_a
)
)
)
(t (setq comma_go nil))
)
(if comma_go
(progn
(setq comma_f "")
(while (> comma_e 3)
(setq
comma_f (strcat "," (substr comma_d (- comma_e 2)) comma_f)
comma_d (substr comma_d 1 (- comma_e 3))
comma_e (- comma_e 3)
)
)
(setq comma_f (strcat comma_d comma_f temp_end))
comma_f
)
nil
)
)



"Kenny Poong" <kennypmw@time.net.my> wrote in message
news:41e4d79f_1@newsprd01...
Quote:
Hi NG,

I use the lisp below to help me to add up the selected numbers.

I would like to have comma for the total. ( 1,000 instead of 1000 )

Can some one help me to correct it ?

TIA.


(defun C:Add (/ p l n e as s tot)
(setq tot 0 p (ssget)) ; Select objects
(if p (progn ; If any objects selected
(setq l 0 n (sslength p))
(while (< l n) ; For each selected
object...
(if (= "TEXT" ; Look for TEXT entity
type
(group 0)
(cdr (assoc 0 (setq e (entget (ssname p l)))))
)
(progn
(setq s (stripit "," (cdr (setq as (assoc 1 e)))))
(setq tot (+ (atof s) tot))
)
)
(setq l (1+ l))
)
)
)
(princ (strcat "\nTotal: " (rtos tot 2 4))) ; second 4 sets number of
decimal places
(setq at (car (entsel "\. Select entity to change to new total or
enter\n")))
(if at
(progn
(setq enl (entget at))
(setq e (subst (cons 1 (rtos tot 2 4)) (assoc 1 enl) enl))
(entmod e)
(princ)
)
)
)
(defun stripit (schar sstring / ptr ctr fnd ts)
(setq ptr (strlen sstring)
ctr 0
fnd nil
ts ""
)
(repeat ptr
(setq ctr (+ 1 ctr))
(setq fnd (= (substr sstring ctr 1) schar))
(if (not fnd)
(setq ts (strcat ts (substr sstring ctr 1)))
)
)
)

Back to top
Kenny Poong
Guest





Posted: Fri Jan 14, 2005 8:25 am    Post subject: Re: Help Needed Reply with quote

Hi Josh,

Thanks for your reply.

Actually I'm new in LISP....how can I "format <comma_a> as a STRING with
RTOS" ?


"Josh" <joshc96@hotmail.com> wrote in message news:41e53f3c_3@newsprd01...
Quote:
Here is a crude function I wrote years ago when I was very new to Lisp and
I
haven't touched it since (it works fine for the rare occasion I use
it...hmmm, I should rewrite it soon)

;;;formats an INTEGER into the "X,XXX,XXX" format (thousands) as a string
;;; 1234 returns "1,234"
;;; 1234.56 returns "1,234"
;;; "1234.56" returns "1,234.56"
;;;if you want a REAL returned you must format <comma_a> as a STRING with
RTOS
(defun commatize (comma_a / comma_go comma_b
comma_c comma_d comma_e comma_f
cnt temp_beg temp_end
)
(setq comma_go t
temp_beg ""
temp_end ""
)
(cond
((or (= (type comma_a) 'int) (= (type comma_a) 'real))
(setq
comma_b (fix comma_a)
comma_d (itoa comma_b)
comma_e (strlen comma_d)
)
)
((= (type comma_a) 'str)
(progn
(setq cnt 1)
(if (wcmatch comma_a "*`.*")
(progn
(while (/= (substr comma_a cnt 1) ".")
(setq
temp_beg (strcat temp_beg (substr comma_a cnt 1))
cnt (1+ cnt)
temp_end (substr comma_a cnt)
)
)
(setq comma_a temp_beg)
)
)
(setq
comma_e (strlen comma_a)
comma_d comma_a
)
)
)
(t (setq comma_go nil))
)
(if comma_go
(progn
(setq comma_f "")
(while (> comma_e 3)
(setq
comma_f (strcat "," (substr comma_d (- comma_e 2)) comma_f)
comma_d (substr comma_d 1 (- comma_e 3))
comma_e (- comma_e 3)
)
)
(setq comma_f (strcat comma_d comma_f temp_end))
comma_f
)
nil
)
)



"Kenny Poong" <kennypmw@time.net.my> wrote in message
news:41e4d79f_1@newsprd01...
Hi NG,

I use the lisp below to help me to add up the selected numbers.

I would like to have comma for the total. ( 1,000 instead of 1000 )

Can some one help me to correct it ?

TIA.


(defun C:Add (/ p l n e as s tot)
(setq tot 0 p (ssget)) ; Select objects
(if p (progn ; If any objects
selected
(setq l 0 n (sslength p))
(while (< l n) ; For each selected
object...
(if (= "TEXT" ; Look for TEXT entity
type
(group 0)
(cdr (assoc 0 (setq e (entget (ssname p l)))))
)
(progn
(setq s (stripit "," (cdr (setq as (assoc 1 e)))))
(setq tot (+ (atof s) tot))
)
)
(setq l (1+ l))
)
)
)
(princ (strcat "\nTotal: " (rtos tot 2 4))) ; second 4 sets number
of
decimal places
(setq at (car (entsel "\. Select entity to change to new total or
enter\n")))
(if at
(progn
(setq enl (entget at))
(setq e (subst (cons 1 (rtos tot 2 4)) (assoc 1 enl) enl))
(entmod e)
(princ)
)
)
)
(defun stripit (schar sstring / ptr ctr fnd ts)
(setq ptr (strlen sstring)
ctr 0
fnd nil
ts ""
)
(repeat ptr
(setq ctr (+ 1 ctr))
(setq fnd (= (substr sstring ctr 1) schar))
(if (not fnd)
(setq ts (strcat ts (substr sstring ctr 1)))
)
)
)



Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> Customization All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Contact Us
Powered by phpBB