;;program name : 캐드내 사칙연산프로그램 ver 1.1
;;date:2000.03.24
;;UPdate:2002.09.30
;;program by:kang o nam
;;E-MAIL : kang0669@chollian.net
;; anold88@hanmail.net
(defun exe1()
(setvar “cmdecho” 0)
(setvar “blipmode” 0)
(setq cl (getvar “clayer”))
(setq e1 (entsel “n>>첫번째숫자선택:”))
(setq a (car e1);;———-엔티티의 이름값
b (entget a);;——–엔티티의 리스트값
txt1 (assoc 1 b);;—-엔티티중 해당 문자열 리스트
tt1 (cdr txt1);;——엔티티 문자열의 리스트중 뒤의값=”문자열”
sum1 (atof tt1);;—–엔티티의 문자열을 정수로 변환=100
txth1 (assoc 40 b);;–엔티티 리스트중 텍스트 높이의 리스트값(40,100)
thh (cdr txth1);;—–엔티티의 텍스트높이의 리스트중 뒤의값=100
)
(setq e2 (entsel “n>>두번째숫자선택:”))
(setq aa (car e2)
bb (entget aa)
txt2 (assoc 1 bb)
tt2 (cdr txt2)
sum2 (atof tt2)
)
(setq tl (assoc 8 b)
txtst (cdr tl)
)
)
(defun exe+()
(setq sum (+ sum1 sum2))
(setq summ (rtos sum 2 3))
(setq p1 (getpoint “n>>표시할 포인트찍기:”))
(command “layer” “s” “7” “”)
(command “text” “s” “ghs” p1 thh 0 summ)
(command “layer” “s” cl “”)
)
(defun exe-()
(setq sum (- sum1 sum2))
(setq summ (rtos sum 2 3))
(setq p1 (getpoint “n>>표시할 포인트찍기:”))
(command “layer” “s” “7” “”)
(command “text” “s” “ghs” p1 thh 0 summ)
(command “layer” “s” cl “”)
)
(defun exe*()
(setq sum (* sum1 sum2))
(setq summ (rtos sum 2 3))
(setq p1 (getpoint “n>>표시할 포인트찍기:”))
(command “layer” “s” “7” “”)
(command “text” “s” “ghs” p1 thh 0 summ)
(command “layer” “s” cl “”)
)
(defun exe/()
(setq sum (/ sum1 sum2))
(setq summ (rtos sum 2 3))
(setq p1 (getpoint “n>>표시할 포인트찍기:”))
(command “layer” “s” “7” “”)
(command “text” “s” “ghs” p1 thh 0 summ)
(command “layer” “s” cl “”)
)
(defun exe%()
(setq sum (* (/ sum1 sum2) 100))
(setq summ (rtos sum 2 3))
(setq p1 (getpoint “n>>표시할 포인트찍기:”))
(command “layer” “s” “7” “”)
(command “text” “s” “ghs” p1 thh 0 summ)
(command “layer” “s” cl “”)
)
(defun c:+( / cl e1 a b txt1 tt1 sum1 txth1 thh e2 aa bb txt2 tt2 sum2 tl txtst sum summ p1)
(exe1)
(exe+)
(princ)
)
(defun c:-( / cl e1 a b txt1 tt1 sum1 txth1 thh e2 aa bb txt2 tt2 sum2 tl txtst sum summ p1)
(exe1)
(exe-)
(princ)
)
(defun c:*( / cl e1 a b txt1 tt1 sum1 txth1 thh e2 aa bb txt2 tt2 sum2 tl txtst sum summ p1)
(exe1)
(exe*)
(princ)
)
(defun c:/( / cl e1 a b txt1 tt1 sum1 txth1 thh e2 aa bb txt2 tt2 sum2 tl txtst sum summ p1)
(exe1)
(exe/)
(princ)
)
(defun c:%( / cl e1 a b txt1 tt1 sum1 txth1 thh e2 aa bb txt2 tt2 sum2 tl txtst sum summ p1)
(exe1)
(exe%)
(princ)
)
(defun c:py( / cl e1 a b txt1 tt1 sum1 txth1 thh sum summ p1 )
(setvar “cmdecho” 0)
(setvar “blipmode” 0)
(setq cl (getvar “clayer”))
(setq e1 (entsel “n>>숫자선택:”))
(setq a (car e1);;———-엔티티의 이름값
b (entget a);;——–엔티티의 리스트값
txt1 (assoc 1 b);;—-엔티티중 해당 문자열 리스트
tt1 (cdr txt1);;——엔티티 문자열의 리스트중 뒤의값=”문자열”
sum1 (atof tt1);;—–엔티티의 문자열을 정수로 변환=100
txth1 (assoc 40 b);;–엔티티 리스트중 텍스트 높이의 리스트값(40,100)
thh (cdr txth1);;—–엔티티의 텍스트높이의 리스트중 뒤의값=100
)
(setq sum (/ sum1 3.3058))
(setq summ (rtos sum 2 3))
(setq zz (strcat “(” summ “)”))
(setq p1 (getpoint “n>>표시할 포인트찍기:”))
(command “layer” “s” “7” “”)
(command “text” “s” “ghs” p1 thh 0 zz)
(command “layer” “s” cl “”)
(princ)
)
(defun c:++( / cl sum_m ss ok e ent sum_ p1 txth1 thh summ )
(setvar “cmdecho” 0)
(setvar “blipmode” 0)
(setq cl (getvar “clayer”))
(setq sum_m 0)
(setq SS (ssget))
(setq ok 0)
(while
(setq e (ssname ss ok))
(setq ent (entget e))
(setq sum_ (assoc 1 ent))
(setq sum_ (cdr sum_))
(setq sum_ (atof sum_))
(setq sum_m (+ sum_m sum_))
(setq ok (1+ ok))
)
(setq p1 (getpoint “n>>표시할 포인트찍기:”))
(command “layer” “s” “7” “”)
(setq txth1 (assoc 40 ent))
(setq thh (cdr txth1))
(setq summ (rtos sum_m 2 3))
(command “text” “s” “ghs” p1 thh 0 summ)
(command “layer” “s” cl “”)
(princ)
)
(defun c:**( / cl sum_m ss ok e ent sum_ p1 txth1 thh summ )
(setvar “cmdecho” 0)
(setvar “blipmode” 0)
(setq cl (getvar “clayer”))
(setq sum_m 1)
(setq SS (ssget))
(setq ok 0)
(while
(setq e (ssname ss ok))
(setq ent (entget e))
(setq sum_ (assoc 1 ent))
(setq sum_ (cdr sum_))
(setq sum_ (atof sum_))
(setq sum_m (* sum_m sum_))
(setq ok (1+ ok))
)
(setq p1 (getpoint “n>>표시할 포인트찍기:”))
(command “layer” “s” “7” “)
(setq txth1 (assoc 40 ent))
(setq thh (cdr txth1))
(setq summ (rtos sum_m 2 3))
(command “text” “s” “ghs” p1 thh 0 summ)
(command “layer” “s” cl “”)
(princ)
)
(princ “n>>사칙연산 프로그램 로딩완료 command : +,-,*,/,%,py,++,**”)
(princ)
위 프로그램을 사용하다보니까여 어떤도면에서는 소수점이
안나오구 어떤 도면에선 소수점이 셋째자리까지 나와여
예를들어 100 + 100 을 하면 200.000으로여
계산식에서 소수점을 지정하는게 있나요
고수님들의 대답기다립니다
K_tum
감사합니다 잘 수정해서 쓰겠습니다
rtos 함수에 대해 공부해 보시길…
(rtos sum_m 2 3) 이게 3자리… (rtos sum_m 2 2) 이게 두자리… 수정은 본인에 맞게 알아서…
리습이 아니라 캐드 기본 명령중 cal 이란 명령어로도 충분히 간단한 계산이 가능합니다. 예) ((3*5)+(2-1))/2 라고 입력할때 8이라는 답이 나옵니다.