TextCalcV1 01
TextCalcV1 01
TextCalcV1 01
;; ;;
;; Allows the user to perform arithmetical operations on ;;
;; numerical data within text. ;;
;; ;;
;; User is prompted to select text containing numerical data ;;
;; then either choose an arithmetical operation or place ;;
;; the result of the current calculation in the form of an ;;
;; MText object in the drawing. ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright � 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Version 1.01 - 12-12-2022 ;;
;; modified for user to show calculation ;;
;; https://www.cadtutor.net/forum/topic/76461-about-textcalculator-lisp/#comment-
605587 ;;
;; Version 1.0 - 07-04-2011 ;;
;; First Release. ;;
;; First Release. ;;
;;------------------------------------------------------------;;
(defun c:TextCalc ( / *error* _StartUndo _EndUndo _Select _Str a acdoc dcf dch f
file num ops pt regex str tmp ) (vl-load-com)
(defun _str ( n )
(cond
( (eq 'INT (type n)) (itoa n))
( (eq 'REAL (type n)) (rtos n))
( (eq 'STR (type n)) n)
( (vl-princ-to-string n))
)
)
(cond
(
(not
(and (setq file (open (setq tmp (vl-filename-mktemp nil nil ".dcl")) "w"))
(foreach line
'(
"_button : image_button { width = 8.33; height = 3.85; fixed_width =
true; fixed_height = true; alignment = centered; color = -15; }"
""
"textcalc : dialog { key = \"dcltitle\"; spacer;"
" : row {"
" : _button { label = \"+\"; key = \"+\"; }"
" : _button { label = \"-\"; key = \"-\"; }"
" : _button { label = \"�\"; key = \"*\"; }"
" : _button { label = \"�\"; key = \"/\"; }"
" }"
" spacer;"
" : button { key = \"accept\"; label = \"Place Result >>\";
is_default = true; height = 2; fixed_height = true; }"
" : button { key = \"cancel\"; label = \"Cancel\";
is_cancel = true; }"
"}"
)
(write-line line file)
)
(not (setq file (close file))) (< 0 (setq dch (load_dialog tmp)))
)
)
(setq str (_str num) ops '(("+" . " + ") ("-" . " - ") ("*" . " � ") ("/" . "
� ")))
(setq dcf 0)
(princ "\n--> Error Loading Dialog.")
)
(t
(foreach x
'(
("+"
(033 032 031 030 029 028 028 028 027 026 025 024 023 022 022 022
021 020 019 018 017 016 015 014 013 012 011 010 009 041 040 039 038
037 036 035 034)
(027 027 027 027 027 011 027 041 041 041 041 041 041 011 027 041
027 027 027 027 027 027 027 027 027 027 028 029 029 029 029 028 027
027 027 027 027)
(023 023 023 023 023 009 023 039 009 009 009 009 009 009 023 039
023 023 023 023 023 023 023 023 023 023 022 021 021 021 021 022 023
023 023 023 023)
)
("-"
(037 036 035 034 033 032 031 030 029 028 027 026 025 024 023 022
021 020 019 018 017 016 015 014 013 012 011 010 009 041 040 039 038)
(027 027 027 027 027 027 027 027 027 027 027 027 027 027 027 027
027 027 027 027 027 027 027 027 027 027 028 029 029 029 029 028 027)
(023 023 023 023 023 023 023 023 023 023 023 023 023 023 023 023
023 023 023 023 023 023 023 023 023 023 022 021 021 021 021 022 023)
)
("/"
(027 026 026 026 025 025 025 024 024 024 023 023 023 022 022 022
021 020 019 018 017 016 015 014 013 012 011 010 009 041 040 039 038
037 036 035 034 033 032 031 030 029 028 028 028 027 027)
(041 016 027 041 016 027 041 016 027 041 015 027 040 014 027 039
027 027 027 027 027 027 027 027 027 027 028 029 029 029 029 028 027
027 027 027 027 027 027 027 027 027 014 027 039 015 027)
(035 009 023 034 009 023 034 009 023 034 009 023 035 011 023 036
023 023 023 023 023 023 023 023 023 023 022 021 021 021 021 022 023
023 023 023 023 023 023 023 023 023 011 023 036 009 023)
)
("*"
(027 026 025 024 023 022 022 021 021 020 020 019 019 018 018 017
017 016 016 015 015 014 014 013 013 012 012 011 011 040 040 039 039
038 038 037 037 036 036 035 035 034 034 033 033 032 032 031 031
030 030 029 029 028)
(030 029 028 029 030 025 031 024 032 023 033 022 034 021 035 020
036 019 039 018 040 017 039 016 038 016 037 016 036 015 035 016 036
016 037 016 038 017 039 018 040 019 037 020 036 021 035 022 034
023 033 024 032 031)
(020 021 022 021 020 019 025 018 026 017 027 016 028 015 029 014
030 010 031 010 032 011 033 012 034 013 034 014 034 015 035 014 034
013 034 012 034 011 033 010 032 013 031 014 030 015 029 016 028
017 027 018 026 019)
)
)
(start_image (car x))
(apply 'mapcar (cons '(lambda ( x y z ) (vector_image x y x z 178))
(cdr x)))
(end_image)
(action_tile (car x) (strcat "(princ (strcat \"\n\" str (cdr (assoc
(setq f $key) ops)))) (done_dialog 2)"))
)
(set_tile "dcltitle" "Text Calculator")
(if (and (= 1 dcf) (setq pt (getpoint "\nSpecify Point for Result: ")))
(progn
(_StartUndo acdoc)
(vla-AddMtext
(vlax-get-property acdoc
(if (= 1 (getvar 'CVPORT)) 'Paperspace 'Modelspace)
)
(vlax-3D-point (trans pt 1 0)) 0. x
)
(_EndUndo acdoc)
)
)
)
)
(*error* nil)
(princ)
)
(defun LM:ParseNumbers ( s )
(
(lambda ( l )
(read
(strcat "("
(vl-list->string
(mapcar
(function
(lambda ( a b c )
(if
(or
(< 47 b 58)
(and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
(and (= 46 b) (< 47 a 58))
(= 32 b)
)
b 32
)
)
)
(cons nil l) l (append (cdr l) (list nil))
)
)
")"
)
)
)
(vl-string->list s)
)
)
(cond
(
(not
(and (setq file (open (setq tmp (vl-filename-mktemp nil nil ".dcl")) "w"))
(write-line
(strcat "listbox : dialog { label = \"" title
"\"; spacer; : list_box { key = \"list\"; multiple_select = "
(if multiple "true" "false") "; } spacer; ok_cancel;}"
)
file
)
(not (close file)) (< 0 (setq dch (load_dialog tmp))) (new_dialog
"listbox" dch)
)
)
)
(
t
(start_list "list")
(mapcar 'add_list data) (end_list)
(setq return
(if (= 1 (start_dialog))
(mapcar '(lambda ( x ) (nth x data)) (read (strcat "(" return ")")))
)
)
)
)
return
)
(and
(eq "ATTRIB" (cdr (assoc 0 (entget entity))))
(vlax-property-available-p (setq object (vlax-ename->vla-object entity))
'MTextAttribute)
(eq :vlax-true (vla-get-MTextAttribute object))
)
)
)
(
(lambda ( string )
(mapcar
(function
(lambda ( pair )
(if (member (car pair) '(1 3))
(setq string (strcat string (cdr pair)))
)
)
)
elist
)
string
)
""
)
)
)
)
entity
)
)
(
(lambda ( string )
(if string
(progn
(mapcar
(function
(lambda ( x ) (vlax-put-property RegExp (car x) (cdr x)))
)
(list (cons 'global actrue) (cons 'ignorecase acfalse) (cons 'multiline
actrue))
)
(if (_AllowsFormatting entity)
(mapcar
(function
(lambda ( x ) (setq string (_Replace (car x) (cdr x) string)))
)
'(
("�" . "\\\\\\\\")
(" " . "\\\\P|\\n|\\t")
("$1" . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW]
[^\\\\;]*;|\\\\[ACcFfHLlOopQTW]")
("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")
("$1$2" . "\\\\(\\\\S)|[\\\\](})|}")
("$1" . "[\\\\]({)|{")
)
)
(setq string (_Replace "" "%%[OoUu]" (_Replace "�" "\\\\" string)))
)
(set *mtextstring (_Replace "\\\\" "�" (_Replace "\\$1$2$3" "(\\\\
[ACcFfHLlOoPpQSTW])|({)|(})" string)))
(set *dtextstring (_Replace "\\" "�" string))
)
)
)
(_GetTextString entity)
)
nil
)
;;------------------------------------------------------------;;
(princ)
(princ "\n:: TextCalc.lsp | Version 1.0 | � Lee Mac 2011 www.lee-mac.com ::")
(princ "\n:: Type \"TextCalc\" or \"TC\" to Invoke ::")
(princ)
;;------------------------------------------------------------;;
;; End of File ;;
;;------------------------------------------------------------;;