BIGAL 发表于 2022-7-5 17:44:21

1线2线3线dcl自动g

很多时候你会看到一个lisp一个接一个地问问题,输入L,输入W,输入H。
 
那么,为什么不能从lisp中的一行(可能是5或6个条目)简单地调用dcl呢。完全定制即时标题描述和字符框大小。这是用于跨任何lisp用作库函数的。慢慢地,我改变了我们的Lisp程序,更好的是使用dcl没有上下屏幕条目。
 
无论如何,这里是getval1 2和3,只需加载它并用一行代码调用它。下面的代码中包含了示例调用。它返回Val1 val2 val3等字符串供您使用,只需将代码另存为“Getvals.lsp”
 

 
; this is a 3 line example of code
(defun c:test ()
(if (not AH:getval3)(load "getvals"))
(ah:getval3 "Enter Length" 8 7 "Enter width"6 5 "Enter height" 6 5)
(setq pt (Getpoint "\nPick lower left corner"))
(command "rectang" PT "D" (atof Val1) (atof Val2) pt)
(command "extrude" "L" "" (atof val3))
(command "Vpoint" (list 1 1 1 ))
)

 

; InputDialog box with variable title
; By Ah June 2015
; credit to Alan J Thompson for original idea
;code just use these next two lines
; (if (not AH:getval1)(load "getvals"))
; (ah:getval1 "title" width limit);

; 1 line dcl
; sample code (ah:getval1 "line 1" 5 4)
(defun AH:getval1 (title width limit / fo)
(setq fname (strcat (getvar "SAVEFILEPATH") "\\getval1.dcl")) ; choose 1 of these file locations
;(setq fname (strcat (getenv "TEMP") "\\getval1.dcl")) ; temp directory defined in support paths
;(setq fname "C:\\acdatemp\\getval1.dcl") ; a existing directory you use
(setq fo (open fname "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))
;(setq dcl_id (load_dialog"c:\\acadtemp\\getval1"))
(if (not (new_dialog "ddgetval" dcl_id))
(exit))
(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
(alert val1)
)


; 2 line dcl
; sample code (ah:getval2 "line 1" 5 4 "line2" 8 7)

(defun AH:getval2 (title1 width1 limit1 title2 width2 limit2 / fo)
(setq fname (strcat (getvar "SAVEFILEPATH") "\\getval2.dcl"))
; choose 1 of these file locations
;(setq fname (strcat (getenv "TEMP") "\\getval2.dcl")) ; temp directory defined in support paths
;(setq fname "C:\\acdatemp\\getval2.dcl") ; a existing directory you use
(setq fo (open fname "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)
(action_tile "key1" "(setq val1 $value)")
(mode_tile "key2" 3)
(action_tile "key2" "(setq val2 $value)")

(start_dialog)
(done_dialog)
(unload_dialog dcl_id)
; returns the value of val1 and val2 as strings
(alert (strcat val1 "\n" val2)); remove this line in finished code
)

; 3 line dcl
; sample code (ah:getval3 "line 1" 5 4 "line2" 8 7 "line3" 6 4)

(defun AH:getval3 (title1 width1 limit1 title2 width2 limit2 title3 width3 limit3 / fo)
(setq fname (strcat (getvar "SAVEFILEPATH") "\\getval3.dcl")) ; choose 1 of these file locations
;(setq fname (strcat (getenv "TEMP") "\\getval3.dcl")) ; temp directory defined in support paths
;(setq fname "C:\\acdatemp\\getval3.dcl") ; a existing directory you use
(setq fo (open fname "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)
(action_tile "key1" "(setq val1 $value)")
(mode_tile "key2" 3)
(action_tile "key2" "(setq val2 $value)")
(mode_tile "key3" 3)
(action_tile "key3" "(setq val3 $value)")
(start_dialog)
(done_dialog)
(unload_dialog dcl_id)
; returns the value of val1 and val2 val3 as strings
(alert (strcat val1 "\n" val2 "\n" val3)); remove this line in finished code
)

tombu 发表于 2022-7-5 17:47:59

美好的我只在一些例程中添加了dcl,没有生成lisp。我没有要尝试的“c:\\acadtemp”文件夹(getvar“SAVEFILEPATH”)

AIberto 发表于 2022-7-5 17:53:36

是的,很好,但是,我想我需要一些例子。

tombu 发表于 2022-7-5 17:56:41

它基本上是一个文件中的3个示例-用于1、2或3个输入的AH:getval1、AH:getval2和AH:getval3,允许您通过调用设置对话框的大小。使用以下示例调用之一后
从临时文件夹中打开dcl文件以将其签出。

tombu 发表于 2022-7-5 17:58:17

将其更改为使用默认的AutoCAD temp文件夹,因为我没有“C://acadtemp”文件夹:
;| InputDialog box with variable title
By Ah June 2015
http://www.cadtutor.net/forum/showthread.php?93002-1-line-2-line-3line-dcl-auto-generator-plus-more-if-required&p=636641&viewfull=1#post636641
Modified to use (getenv "temp") by Tom Beauford
code just use these next two lines
(if (not AH:getval1)(load "getvals"))
(ah:getval1 "title" width limit)|;

; 1 line dcl
; sample code(ah:getval1 "line 1" 5 4)
(defun AH:getval1 (title width limit / fname fo dcl_id val1)
(setq fname (strcat (getenv "temp") "\\getval1.dcl"))
(setq fo (open fname "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))
;(setq dcl_id (load_dialog"c:\\acadtemp\\getval1"))
(if (not (new_dialog "ddgetval" dcl_id))
(exit))
(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
(alert val1)
)


; 2 line dcl
; sample code (ah:getval2 "line 1" 5 4 "line2" 8 7)

(defun AH:getval2 (title1 width1 limit1 title2 width2 limit2 / fname fo dcl_id val1 val2)
(setq fname (strcat (getenv "temp") "\\getval2.dcl"))
(setq fo (open fname "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)
(action_tile "key1" "(setq val1 $value)")
(mode_tile "key2" 3)
(action_tile "key2" "(setq val2 $value)")

(start_dialog)
(done_dialog)
(unload_dialog dcl_id)
; returns the value of val1 and val2 as strings
(alert (strcat val1 " " val2))
)

; 3 line dcl
; sample code (ah:getval3 "line 1" 5 4 "line2" 8 7 "line3" 6 4)

(defun AH:getval3 (title1 width1 limit1 title2 width2 limit2 title3 width3 limit3 / fname fo dcl_id val1 val2 val3)
(setq fname (strcat (getenv "temp") "\\getval3.dcl"))
(setq fo (open fname "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)
(action_tile "key1" "(setq val1 $value)")
(mode_tile "key2" 3)
(action_tile "key2" "(setq val2 $value)")
(mode_tile "key3" 3)
(action_tile "key3" "(setq val3 $value)")
(start_dialog)
(done_dialog)
(unload_dialog dcl_id)
; returns the value of val1 and val2 val3 as strings
(alert (strcat val1 "\n" val2 "\n" val3))
)

BIGAL 发表于 2022-7-5 18:03:08

不用担心,tombu,我们每个人都有一个本地临时目录,它是我们个人资料的一部分,我已经更改了我原来的帖子,但为了您的信息,需要更改路径名的双反斜杠\\getval1。

tombu 发表于 2022-7-5 18:04:25

 
返回“C:\\Users\\BeaufordT\\appdata\\local\\temp\”,结尾带有双反斜杠
返回“C:\\Users\\BeaufordT\\appdata\\local\\temp\\getval1.dcl”,而
虽然
返回“C:\\Users\\BeaufordT\\appdata\\local\\temp\\\getval1.dcl”
 
经过进一步思考
返回“C:\\Users\\BEAUFO~1\\AppData\\Local\\Temp”的更好,因为SAVEFILEPATH是保存autosave sv$文件的地方。通常情况下,您可以在不更改临时文件夹位置的情况下更改SAVEFILEPATH。所以我把它改成了
在我之前的帖子中。

stevesfr 发表于 2022-7-5 18:09:06

 
AL,getval。2012年推出的lsp完美无瑕。我无法获取getvals。lsp将dcl文件写入我的临时目录(我已正确设置)中,以了解我可能做错的任何建议或示例。
史蒂夫

BIGAL 发表于 2022-7-5 18:10:35

Tombu有趣得到不同的结果
 
命令:(strcat(getvar“SAVEFILEPATH”)“\\getval1.dcl”)
“C:\\AcadTemp\\getval1.dcl”
 
命令:(getvar“SAVEFILEPATH”)
“C:\\AcadTemp”
 
 
(strcat(getvar“SAVEFILEPATH”)“getval1.dcl”)
“C:\\AcadTempgetval1.dcl”

BIGAL 发表于 2022-7-5 18:14:59

stevesfr最简单的方法是对目录进行硬编码,我们有一个c:\Acadtemp,这是我首先发布的,然后将代码更改为更通用,因为另一个发布的目录没有Acadtemp。
 
9
页: [1] 2
查看完整版本: 1线2线3线dcl自动g