geomcal.arx的cal自带四则运算功能,使用举例如下;
批量四则运算
- (vl-load-com)
- ;;加载geomcal.arx
- (if (not(member "GEOMCAL.ARX" (mapcar (function strcase) (arx))))
- (arxload (findfile "geomcal.arx"))
- )
- (defun c:szys (/ ws ss ssen cal_str ent str x)
- (prompt
- "\n计算表达式文字自身数值为变量x,形如x-0.05、(x^2-1)/2"
- )
- (setq ws (getint "\n请输入小数点后位数<3>"))
- (if (not ws)
- (setq ws 3)
- )
- (prompt "\n选择需要数值运算的文字")
- (setq ss (ssget (list (cons 0 "TEXT"))))
- ;_(svos)
- (if
- (and ss
- (setq ssen (ss2lst ss nil))
- (setq ssen (vl-remove-if-not
- (function (lambda (x)
- (numberp (read (dxf 1 x)))
- )
- )
- ssen
- )
- )
- )
- (if
- (and (setq cal_str (vl-string-trim " " (LM:GetString "x-0.05")))
- (/= cal_str "")
- )
- (foreach a ssen
- (setq ent (entget a)
- str (dxf 1 ent)
- x (atof str)
- )
- (if x
- (setq x (vl-catch-all-apply (function cal) (list cal_str)))
- )
- (if (vl-catch-all-error-p x)
- (princ (vl-catch-all-error-message x))
- (progn
- (setq str (rtos x 2 ws))
- (setq ent (ch-en (cons 1 str) ent))
- (entmod ent)
- )
- )
- )
- (princ "\n未输入表达式")
- )
- (princ "\n选择错误.")
- )
- ;_(clos)
- (princ)
- )
- ;;;by Lee Mac
- (defun LM:GetString (#Default / dcTag result)
- (cond ( (<= (setq dcTag (load_dialog "ACAD")) 0))
- ( (not (new_dialog "acad_txtedit" dcTag)))
- (t
- (set_tile "text_edit" #Default)
- (action_tile "accept" "(setq result (get_tile "text_edit")) (done_dialog)")
- (action_tile "cancel" "(done_dialog)")
- (start_dialog)
- (unload_dialog dcTag)))
- result)
- ;;;转换选择集为表
- (defun ss2lst (ss vla / a e i)
- (if (= (type ss) (quote PICKSET))
- (progn
- (setq i -1)
- (while (setq e (ssname ss (setq i (1+ i))))
- (if vla
- (setq e (vlax-ename->vla-object e))
- nil
- )
- (setq a (cons e a))
- )
- )
- nil
- )
- )
- ;;索引点表值
- (defun dxf (co en)
- (if(eq(type en)(quote ENAME))(setq en(entget en(quote("*")))))
- (if(vl-consp co)(mapcar (function (lambda (x)(cdr (assoc x en))))co)
- (cdr (assoc co en))))
- ;;点表替换
- (defun ch-en (co en /)
- (if (eq (type en) (quote ename))
- (setq en (entget en (list "*")))
- )
- (if (assoc (car co) en)
- (subst co (assoc (car co) en) en)
- (reverse (cons co (reverse en)))
- )
- )
|