打印字段公式内容
你好使用acad 2017
我得到了一个简单的公式,可以进行数学运算并打印出结果,
但我希望它能打印出整个公式和结果。
怎么做?
见附件
field_frml。图纸 可以这样做,例如对于使用cond类型的字符串4.83 x 7.05的4个简单计算,查找x-+/然后将文本拆分为num1 num2和数学。
definatley not tested
(setq num1 (getreal "enter 1st value"))
(setq num2 (getreal "enter 2nd value"))
(setq math (getstring "enter math value"))
(cond
((= (strcase math) "X")(setq ans (strcat (rtos num1 2 2 ) " " math " " (rtos num2 2 2) " = " (rtos (* num1 num2) 2 2 )))))
... same for + - /
)
(command "Text" pt "" "" ans)
谢谢比格尔。我希望用更友好的方式来做,但Lisp程序是一个真正的解决方案,
毕竟,Feilds是为非程序员服务的
再次感谢
Lisp我来了
谢伊 这是一个dcl前端,第三行是*/-+
(ah:getval3“1st number”5 4“1”“2nd number”8 7“2”“数学运算+-/*”6 4“*”) 这是一个更新版本需要getvals3。lsp
; Formula as text .lsp
; By Alan H July 2017
(defun mathtxt ( / num1 num2 val1 val2 val3)
(setq decpl 2)
(if (not Ah:getval3)(load "getvals3"))
(ah:getval3 "1st number " 5 4 "1" "2nd number " 8 7 "2" "Math operation + - / *" 6 4 "X")
(setq num1 (atof val1))
(setq num2 (atof val2))
(if(= (strcase val3) "X") (setq ans (strcat val1 " " val3 " " val2 " = " (rtos (* num1 num2) 2 decpl ))))
(if (=val3 "-")(setq ans (strcat val1 " " val3 " "val2 " = " (rtos (- num1 num2) 2 decpl ))))
(if (= val3 "+")(setq ans (strcat val1 " " val3 " "val2" = " (rtos (+ num1 num2) 2 decpl ))))
(if (= val3 "/")(setq ans (strcat val1 " " val3 " "val2" = " (rtos (/ num1 num2) 2 decpl ))))
(command "Text" (getpoint) "" ans) ; text with preset height
;(command "Text" (getpoint) "" "" ans) ;text with no height set
(mathtxt)
; InputDialog box with variable title
; multiple lines of dcl input supported
; add extra lines if required by copying code defun
; By Alan H 2015
(vl-load-com)
; 1 line dcl
; sample code (ah:getval1 "Line 1" 5 4 "-")
(defun AH:getval1 (title width limit def1 / fo fname)
; you can hard code a directory if you like for dcl file
(setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))
;(setq fo (open (setq fname "c:\\acadtemp\\getval.dcl") "w"))
(write-line "ddgetval : dialog {" fo)
(write-line " : row {" fo)
(write-line ": edit_box {" fo)
(write-line (strcat " key = "(chr 34) "key1" (chr 34) ";") fo)
(write-line(strcat " label = "(chr 34) title (chr 34) ";") fo)
; these can be replaced with shorter value etc
(write-line (strcat " edit_width = " (rtos width 2 0) ";" ) fo)
(write-line (strcat " edit_limit = " (rtos limit 2 0) ";" ) fo)
(write-line " is_enabled = true;" fo)
(write-line " }" fo)
(write-line "}" fo)
(write-line "ok_only;}" fo)
(close fo)
(setq dcl_id (load_dialogfname))
; pt is a list 2 numbs -1 -1 centre ('(20 20))
;(not (new_dialog "test" dch "" *screenpoint*))
(if (not (new_dialog "ddgetval" dcl_id))
(exit))
(set_tile "key1" (setq val1 def1))
(action_tile "key1" "(setq val1 $value)")
(mode_tile "key1" 3)
(start_dialog)
(done_dialog)
(unload_dialog dcl_id)
; returns the value of val1 as a string
(vl-file-delete fname)
) ; defungetval1
; 2 line dcl
; sample code (ah:getval2 "Line 1" 5 4 "1" "Line2" 8 7 "2")
(defun AH:getval2 (title1 width1 limit1 def1 title2 width2 limit2 def2 / fo fname)
(setq fo (open (setq fname "c:\\acadtemp\\getval.dcl") "w"))
(write-line "ddgetval2 : dialog {" fo)
(write-line " : column {" fo)
(write-line ": edit_box {" fo)
(write-line (strcat " key = " (chr 34) "key1" (chr 34) ";") fo)
(write-line(strcat " label = "(chr 34) title1 (chr 34) ";" ) fo)
(write-line (strcat " edit_width = " (rtos width1 2 0) ";" ) fo)
(write-line (strcat " edit_limit = " (rtos limit1 2 0) ";" ) fo)
(write-line " is_enabled = true ;" fo)
(write-line " }" fo)
(write-line "spacer_1 ;" fo)
(write-line ": edit_box {" fo)
(write-line (strcat " key = " (chr 34) "key2" (chr 34) ";") fo)
(write-line (strcat " label = "(chr 34) title2 (chr 34) ";") fo)
(write-line (strcat " edit_width = " (rtos width2 2 0) ";" ) fo)
(write-line (strcat " edit_limit = " (rtos limit2 2 0) ";" ) fo)
(write-line " is_enabled = true ;" fo)
(write-line " }" fo)
(write-line " }" fo)
(write-line "spacer_1 ;" fo)
(write-line "ok_only;}" fo)
(close fo)
; code part
(setq dcl_id (load_dialogfname))
(if (not (new_dialog "ddgetval2" dcl_id))
(exit))
(mode_tile "key1" 3)
(set_tile "key1" (setq val1 def1))
(action_tile "key1" "(setq val1 $value)")
(mode_tile "key2" 3)
(set_tile "key2" (setq val2 def2))
(action_tile "key2" "(setq val2 $value)")
(start_dialog)
(done_dialog)
(unload_dialog dcl_id)
; returns the value of val1 and val2 as strings
(vl-file-delete fname)
) ; defungetval2
; 3 line dcl
; sample code (ah:getval3 "Line 1" 5 4 "0.9" "Line 2" 8 7 "wow" "Line 3" 6 4 "123")
(defun AH:getval3 (title1 width1 limit1 def1 title2 width2 limit2 def2 title3 width3 limit3 def3 / fo fname)
(setq fo (open (setq fname "c:\\acadtemp\\getval.dcl") "w"))
(write-line "ddgetval3 : dialog {" fo)
(write-line " : column {" fo)
(write-line ": edit_box {" fo)
(write-line (strcat " key = " (chr 34) "key1" (chr 34) ";") fo)
(write-line(strcat " label = "(chr 34) title1 (chr 34) ";" ) fo)
(write-line (strcat " edit_width = " (rtos width1 2 0) ";" ) fo)
(write-line (strcat " edit_limit = " (rtos limit1 2 0) ";" ) fo)
(write-line " is_enabled = true ;" fo)
(write-line " }" fo)
(write-line "spacer_1 ;" fo)
(write-line ": edit_box {" fo)
(write-line (strcat " key = " (chr 34) "key2" (chr 34) ";") fo)
(write-line (strcat " label = "(chr 34) title2 (chr 34) ";") fo)
(write-line (strcat " edit_width = " (rtos width2 2 0) ";" ) fo)
(write-line (strcat " edit_limit = " (rtos limit2 2 0) ";" ) fo)
(write-line " is_enabled = true ;" fo)
(write-line " }" fo)
(write-line "spacer_1 ;" fo)
(write-line ": edit_box {" fo)
(write-line (strcat " key = " (chr 34) "key3" (chr 34) ";") fo)
(write-line (strcat " label = "(chr 34) title3 (chr 34) ";") fo)
(write-line (strcat " edit_width = " (rtos width3 2 0) ";" ) fo)
(write-line (strcat " edit_limit = " (rtos limit3 2 0) ";" ) fo)
(write-line " is_enabled = true ;" fo)
(write-line " }" fo)
(write-line " }" fo)
(write-line "spacer_1 ;" fo)
(write-line "ok_only;}" fo)
(close fo)
; code part
(setq dcl_id (load_dialogfname))
(if (not (new_dialog "ddgetval3" dcl_id))
(exit))
(mode_tile "key1" 3)
(set_tile "key1" (setq val1 def1))
(action_tile "key1" "(setq val1 $value)")
(mode_tile "key2" 3)
(set_tile "key2" (setq val2 def2))
(action_tile "key2" "(setq val2 $value)")
(mode_tile "key3" 3)
(set_tile "key3" (setq val3 def3))
(action_tile "key3" "(setq val3 $value)")
(start_dialog)
(done_dialog)
(unload_dialog dcl_id)
; returns the value of val1 val2 and val3 as strings
(vl-file-delete fname)
) ; defungetval3
看看李的http://www.lee-mac.com/fieldmath.html
页:
[1]