aloy 发表于 2022-7-5 15:52:31

提示输入默认值

大家好,
我想将一个值(实数)附加到变量作为默认值,并要求用户接受它或输入其他值。如何使用alisp/vlisp实现它?。
 
提前感谢。
 
芦荟

Tharwat 发表于 2022-7-5 16:00:53

你好
例如:

(or *val* (setq *val* 1.0))
(setq *val*
      (cond ((getdist (strcat "\nSpecify Offset distance " (strcat "< " (rtos *val* 2 4) " > :"))))
            (*val*)
            )
   )

aloy 发表于 2022-7-5 16:04:18

非常感谢Tharwat。
 
芦荟

Tharwat 发表于 2022-7-5 16:09:27

欢迎随时光临。

Lee Mac 发表于 2022-7-5 16:13:50

您可能会发现本教程很有用。

BIGAL 发表于 2022-7-5 16:15:30

使用带有用户输入的dcl示例
 

; 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

 

(if (not ah:getval1)(load "getval1"))
(ah:getval1 "Enter a value" 5 4 "6")


GETVALS3.lsp

saim 发表于 2022-7-5 16:19:17

我正在寻找一种方法来做到这一点,谢谢阿洛伊的提问,并感谢所有的答案!
我对“cond”的说法感到困惑。第一个条件以两个括号开始,我找不到解释。我当然是必需的,因为我用简单的括号尝试了代码,但没有成功。但为什么需要?
 
顺便说一句,很高兴了解全局变量的符号。在编程时,我总是尝试使用好习惯,但我是一个自学者,所以没有人教我哪些好习惯是有的。

Tharwat 发表于 2022-7-5 16:23:52

 
你可以阅读这篇文章来了解原因。

saim 发表于 2022-7-5 16:29:20

我会试着用英语输入我从示例代码中读到的内容,如果我错了,你会告诉我,好吗?然后,我想我的怀疑会更清楚。
(cond ;if any of the following conditions is true, here's what will happen
((= s "Y") 1) ;if s equals "Y", then it'll return 1
((= s "y") 1) ;if s equals "y", then it'll return 1
((= s "N") 0) ;if s equals "N", then it'll return 1
((= s "n") 0) ;if s equals "n", then it'll return 1
(t nil); if none of the above is true I'll test if "true" is true (it'll be) and return "nil"
)
您可以看到,在提供的示例中,第二个括号用于测试条件。当我读到这篇文章时,我可以让一个全局变量为true或nil,然后写下如下内容:
 
(cond
(*givenvar* returnVal) ;if the variable is a valid value, return "returnVal"
(t defaulReturnVal) ;otherwise, return "defaulReturnVal"
)
 
现在,对于您的代码,如果条件为true,则没有设置值,并且在默认条件下没有测试(即使在“true”为true时进行测试)。它更简洁,看起来更聪明。我想了解它是如何工作的。

Lee Mac 发表于 2022-7-5 16:32:33

根据文件:
 
页: [1] 2
查看完整版本: 提示输入默认值