Author Topic: This 4 Arithmetic lisp doesn't work with comma(,).  (Read 1961 times)

0 Members and 1 Guest are viewing this topic.

asami486

  • Guest
This 4 Arithmetic lisp doesn't work with comma(,).
« on: February 06, 2017, 02:06:23 AM »
Always Thanks, Theswamp!
This 4 arithmetic lisp doesn't work with comma.
Could this lisp work with comma???



Code - Auto/Visual Lisp: [Select]
  1. ;;program name : 캐드내 사칙연산프로그램 ver 1.0
  2. ;;program : +, -, /, * 가지고 텍스트 계산 다 됨
  3.  
  4.  
  5. (defun exe_1()
  6.    (setvar "cmdecho" 0)
  7.    (setvar "blipmode" 0)
  8.    (setq e1 (entsel "\n>>첫번째숫자선택:"))
  9.    (setq a (car e1);;----------엔티티의 이름값
  10.          b (entget a);;--------엔티티의 리스트값
  11.          txt1 (assoc 1 b);;----엔티티중 해당 문자열 리스트
  12.          tt1 (cdr txt1);;------엔티티 문자열의 리스트중 뒤의값="문자열"
  13.          sum1 (atof tt1);;-----엔티티의 문자열을 정수로 변환=100
  14.          txth1 (assoc 40 b);;--엔티티 리스트중 텍스트 높이의 리스트값(40,100)
  15.          thh (cdr txth1);;-----엔티티의 텍스트높이의 리스트중 뒤의값=100
  16.    )          
  17.    (setq e2 (entsel "\n>>두번째숫자선택:"))
  18.    (setq aa (car e2)
  19.          bb (entget aa)
  20.          txt2 (assoc 1 bb)
  21.          tt2 (cdr txt2)
  22.          sum2 (atof tt2)
  23.          )
  24.     (setq tl (assoc 8 b)
  25.           txtst (cdr tl)
  26.     )
  27. )
  28.  
  29. (defun exe+()
  30.    (setq sum (+ sum1 sum2))
  31.    (setq summ (rtos sum 2 3))
  32.    (setq p1 (getpoint "\n>>표시할 포인트찍기:"))
  33.    (command "text" p1 thh 0 summ)
  34.      
  35.  )
  36. (defun exe-()
  37.    (setq sum (- sum1 sum2))
  38.    (setq summ (rtos sum 2 3))
  39.    (setq p1 (getpoint "\n>>표시할 포인트찍기:"))
  40.    (command "text" p1 thh 0 summ)
  41.  
  42. )
  43.  
  44.  
  45.  (defun exe*()
  46.     (setq sum (* sum1 sum2))
  47.     (setq summ (rtos sum 2 3))
  48.     (setq p1 (getpoint "\n>>표시할 포인트찍기:"))
  49.     (command "text" p1 thh 0 summ)
  50.  )
  51.  
  52.  (defun exe/()
  53.     (setq sum (/ sum1 sum2))
  54.     (setq summ (rtos sum 2 3))
  55.     (setq p1 (getpoint "\n>>표시할 포인트찍기:"))
  56.     (command "text" p1 thh 0 summ)
  57.  )
  58.  (defun exe%()
  59.     (setq sum (* (/ sum1 sum2) 100))
  60.     (setq summ (rtos sum 2 3))
  61.     (setq p1 (getpoint "\n>>표시할 포인트찍기:"))
  62.     (command "text" p1 thh 0 summ)
  63.  )
  64.  
  65. (defun c:+( / e1 a b txt1 tt1 sum1 txth1 thh e2 aa bb txt2 tt2 sum2 tl txtst sum summ p1)
  66.   (exe_1)
  67.   (exe+)
  68.   (princ)
  69. )
  70. (defun c:-( / e1 a b txt1 tt1 sum1 txth1 thh e2 aa bb txt2 tt2 sum2 tl txtst sum summ p1)
  71.    (exe_1)
  72.    (exe-)
  73.    (princ)
  74. )
  75. (defun c:*( / e1 a b txt1 tt1 sum1 txth1 thh e2 aa bb txt2 tt2 sum2 tl txtst sum summ p1)
  76.    (exe_1)
  77.    (exe*)
  78.    (princ)
  79. )
  80. (defun c:/( / e1 a b txt1 tt1 sum1 txth1 thh e2 aa bb txt2 tt2 sum2 tl txtst sum summ p1)
  81.   (exe_1)
  82.   (exe/)
  83.   (princ)
  84. )
  85. (defun c:%( / e1 a b txt1 tt1 sum1 txth1 thh e2 aa bb txt2 tt2 sum2 tl txtst sum summ p1)
  86.   (exe_1)
  87.   (exe%)
  88.   (princ)
  89. )
  90. (defun c:py( / e1 a b txt1 tt1 sum1 txth1 thh sum summ p1 )
  91.    (setvar "cmdecho" 0)
  92.    (setvar "blipmode" 0)
  93.    (setq e1 (entsel "\n>>숫자선택:"))
  94.    (setq a (car e1);;----------엔티티의 이름값
  95.          b (entget a);;--------엔티티의 리스트값
  96.          txt1 (assoc 1 b);;----엔티티중 해당 문자열 리스트
  97.          tt1 (cdr txt1);;------엔티티 문자열의 리스트중 뒤의값="문자열"
  98.          sum1 (atof tt1);;-----엔티티의 문자열을 정수로 변환=100
  99.          txth1 (assoc 40 b);;--엔티티 리스트중 텍스트 높이의 리스트값(40,100)
  100.          thh (cdr txth1);;-----엔티티의 텍스트높이의 리스트중 뒤의값=100
  101.    )
  102.     (setq sum (* sum1 0.3025))
  103.     (setq summ (rtos sum 2 3))
  104.     (setq zz (strcat "(" summ ")"))
  105.     (setq p1 (getpoint "\n>>표시할 포인트찍기:"))
  106.     (command "text" p1 thh 0 zz)
  107. )
  108.  
  109. (defun c:+( / sum_m ss ok e ent sum_ p1 txth1 thh summ )
  110.  (setvar "cmdecho" 0)
  111.  (setvar "blipmode" 0)
  112.  (setq sum_m 0)
  113.   (setq SS (ssget))
  114.   (setq ok 0)
  115.   (while
  116.     (setq e (ssname ss ok))
  117.     (setq ent (entget e))
  118.     (setq sum_ (assoc 1 ent))
  119.     (setq sum_ (cdr sum_))
  120.     (setq sum_ (atof sum_))
  121.     (setq sum_m (+ sum_m sum_))
  122.     (setq ok (1+ ok))
  123.   )
  124.  (setq p1 (getpoint "\n>>표시할 포인트찍기:"))
  125.     (setq txth1 (assoc 40 ent))
  126.     (setq thh (cdr txth1))
  127.     (setq summ (rtos sum_m 2 3))
  128.     (command "text" p1 thh 0 summ)
  129. (princ)      
  130. )
  131.  
  132. (defun c:*( / sum_m ss ok e ent sum_ p1 txth1 thh summ )
  133.  (setvar "cmdecho" 0)
  134.  (setvar "blipmode" 0)
  135.  (setq sum_m 1)
  136.   (setq SS (ssget))
  137.   (setq ok 0)
  138.   (while
  139.     (setq e (ssname ss ok))
  140.     (setq ent (entget e))
  141.     (setq sum_ (assoc 1 ent))
  142.     (setq sum_ (cdr sum_))
  143.     (setq sum_ (atof sum_))
  144.     (setq sum_m (* sum_m sum_))
  145.     (setq ok (1+ ok))
  146.   )
  147.  (setq p1 (getpoint "\n>>표시할 포인트찍기:"))
  148.     (setq txth1 (assoc 40 ent))
  149.     (setq thh (cdr txth1))
  150.     (setq summ (rtos sum_m 2 3))
  151.     (command "text" p1 thh 0 summ)
  152. (princ)      
  153. )
  154. (princ "\n>>사칙연산 프로그램 로딩완료 command : +,-,*,/,%,py,++,**")
  155.  

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: This 4 Arithmetic lisp doesn't work with comma(,).
« Reply #1 on: February 06, 2017, 03:12:42 AM »
Hi,

With AutoLISP, the decimal separator is always the dot (.).
You have to use vl-string-subst to replace the comma with a dot before converting a string into a real number.
Speaking English as a French Frog

asami486

  • Guest
Re: This 4 Arithmetic lisp doesn't work with comma(,).
« Reply #2 on: February 06, 2017, 07:20:29 PM »
I didn't got it.
Could you make a lisp file that function added to?

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2138
  • class keyThumper<T>:ILazy<T>
Re: This 4 Arithmetic lisp doesn't work with comma(,).
« Reply #3 on: February 07, 2017, 02:40:07 AM »
asami486,

Where are the commas located in the strings ?



Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: This 4 Arithmetic lisp doesn't work with comma(,).
« Reply #4 on: February 07, 2017, 02:44:12 AM »
Just replace all (atof xxx) expressions with:
Code - Auto/Visual Lisp: [Select]
  1. (atof (vl-string-subst "." "," xxx))

Could you please reply  to the topics you started about TotalArea and TotalPerim here, at TheSwamp and at CADTutor.

Speaking English as a French Frog

asami486

  • Guest
Re: This 4 Arithmetic lisp doesn't work with comma(,).
« Reply #5 on: February 07, 2017, 07:16:21 PM »
I can't find the "Unblock" at file mouse right click.
Then, I'm holding that lisp studying.
That lisp still doesn't works for me. :cry:

asami486

  • Guest
Re: This 4 Arithmetic lisp doesn't work with comma(,).
« Reply #6 on: February 07, 2017, 07:35:38 PM »
Mr.Gile.
4arithmetic lisp has a little error.
For example,
When I 1,214.29 added to 8,588.20, I got 9.802 as the result.
But The correct value is  9,802.49.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: This 4 Arithmetic lisp doesn't work with comma(,).
« Reply #7 on: February 07, 2017, 09:25:54 PM »
Code - Auto/Visual Lisp: [Select]
  1. (alert (vl-string-subst "" ","  "8,588.20"))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

asami486

  • Guest
Re: This 4 Arithmetic lisp doesn't work with comma(,).
« Reply #8 on: February 07, 2017, 10:43:31 PM »
Thanks Mr.ronjonp.
+ , * of that lisp works for me.
But  -(minus) , /(division) doesn't works for me.
When I commanded - or / function, It showed me a massage, "error: bad function: xxxx"

And When I command +(add), I can't command continually just by a spacebar.
I'd like to command the previous command(add) just by a spacebar.
« Last Edit: February 07, 2017, 10:52:48 PM by asami486 »

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2138
  • class keyThumper<T>:ILazy<T>
Re: This 4 Arithmetic lisp doesn't work with comma(,).
« Reply #9 on: February 08, 2017, 12:18:21 AM »
asami486
REFER Reply #3 ... I asked this question because I suspected you were NOT using  a comma for a decimal.




be aware that vl-string-subst only deals with the FIRST instance of the 'template' it finds.


Perhaps play with something like this.

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (setq data "12,345,678.90")
  3. (distof data) ;;-> nil
  4. (atof data)   ;;-> 12.0
  5.  
  6.  
  7. (setq temp data)
  8.             (setq temp (vl-string-subst "" "," temp)
  9.        )
  10. )
  11.  
  12. (distof temp) ;;-> 1.23457e+07
  13.  
  14. (rtos (distof temp) 2 14) ;;-> "12345678.90000000"
  15.  
« Last Edit: February 08, 2017, 12:21:39 AM by kdub »
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

asami486

  • Guest
Re: This 4 Arithmetic lisp doesn't work with comma(,).
« Reply #10 on: February 08, 2017, 03:57:06 AM »
Thanks kdub.
Can I ask you where I have to add the code to my lisp??

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2138
  • class keyThumper<T>:ILazy<T>
Re: This 4 Arithmetic lisp doesn't work with comma(,).
« Reply #11 on: February 08, 2017, 05:19:53 AM »
Perhaps try something like this :

Add this to the end of your file so it loads with your code :

Code - Auto/Visual Lisp: [Select]
  1. (defun _removecommas-fromstring (str)
  2.   (while (vl-string-search "," str) (setq str (vl-string-subst "" "," str)))
  3.    str
  4. )
  5.  


test it with various values until you're happy :

Code - Auto/Visual Lisp: [Select]
  1. (setq txt2 "12,345,678.90")
  2. (setq sum1 (atof(_removecommas-fromstring txt2) ))
  3.  
  4. ;; ==> 1.23457e+07
  5.  
  6. ;; >>>>>>>>>>etc
  7.  

Then replace all (atof xxx) expressions with:

Code - Auto/Visual Lisp: [Select]
  1. (atof(_removecommas-fromstring xxx) )
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

asami486

  • Guest
Re: This 4 Arithmetic lisp doesn't work with comma(,).
« Reply #12 on: February 08, 2017, 06:07:10 AM »
Thanks. mr kdub :-D
Can I ask one more question if you don't mind?
Could it be possible to add 1000 division comma(,) to the result value(number) of calculation by that lisp?