BIGAL 发表于 2022-7-5 19:46:13

多行DCL自动代码生成器

很多时候,我在lisp中看到多个问题,并认为一个好的dcl会更好,但编写dcl和接口LSP很耗时,所以我试图通过加载一个单独的lisp和几行代码,将两者基本结合起来,从一行输入到dcl支持的尽可能多的代码。
 
无论如何,它如此接近,所以我在这里发布了代码,它自动生成dcl和运行它所需的lsp。我只是有一个作家块和它如此接近。所以,对所有人来说,都很感激。
 

;; writes a multiline input dcl file from generic input
;; By BIG AL May 2015

(defun AH:write-items (keynum title / )
(write-line ": edit_box {" f1)
(write-line (strcat "    key = "(chr 34) Keynum (chr 34) ";") f1)
(write-line(strcat " label = "(chr 34) title (chr 34) ";")   f1)
; these can be replaced with shorter value etc
(write-line "   edit_width = 18;" f1)
(write-line "   edit_limit = 15;" f1)
(write-line "   is_enabled = true;" f1)      
(write-line "    }" f1)

(if (= AHnum nil)(setq AHnum 0))

(write-line (strcat "(action_tile " (chr 34) keynum (chr 34) " " (chr 34) "(setq item" (rtos (setq AHnum (+ AHnum 1)) 2 0) " $value)" (chr 34) ")" ) f2)
)


; this defun writes the first few lines of the lsp and dcl files
(defun AH:openfiles ()

(setq f1 (open "C://acadtemp//getval.dcl" "w"))
(setq f2 (open "C://acadtemp//getvals2.lsp" "w"))
; dcl
(write-line "ddgetval : dialog {" f1)
(write-line (strcat "label = " (chr 34) "Enter values" (chr 34) ";") f1)
(write-line ": column {" f1)

;lsp
(write-line (strcat "(setq dcl_id (load_dialog " (chr 34) "c:\\acadtemp\\getval" (chr 34) "))" ) f2)
(write-line (strcat "(if (not (new_dialog " (chr 34) "ddgetval" (chr 34) " dcl_id))" ) f2)
(write-line "(exit))" f2)

) ; defun

; closes files
;dcl
(defun AH:closefiles ()
(write-line "spacer_1 ;" f1)
(write-line "ok_cancel;}" f1)
(write-line "}" f1)
(close f1)
;lsp
(write-line "(START_DIALOG)" f2)
(write-line "(done_dialog)" f2)
(close f2)
(setq num nil)
)


; this is test code which would be added to a seperate routine asking 4 questions

(AH:openfiles)
(AH:write-items "key1" "Title1") ; (setq ans1 key1)
(AH:write-items "key2" "Title2") ; (setq var1 key2)
(AH:write-items "key3" "Title3") ; (setq var2 key3)
(AH:write-items "key4" "Title4") ; (setq xx key4)
(AH:closefiles)
;(load "C:\\acadtemp\\getvals2") ; it should return 4 values item1 item2 item3 item4
;(alert (strcat item1 "\n" item2 \n item3 \n item4)) ; just a test line

BIGAL 发表于 2022-7-5 21:36:21

以上代码已更新
 
最终结果是DCl具有所需的更少或尽可能多的行,而不是编写或编辑多个DCl
 
页: [1]
查看完整版本: 多行DCL自动代码生成器