这将为您创建DCL。
- ;; YesNo.lsp CAB 04.260.2008
- ;; Creates a DCL file on the fly for Yes/No Prompt
- ;; Arguments:
- ;; BoxTitle = Dialog Box Title
- ;; Question = Question to be displayed
- ;; Sample Call (YesNo " My Yes No" "Do you like creating programs in AutoLISP?")
- ;; Returns "Yes" or "No" from user or nil if the DCL failed
- (defun YesNo (BoxTitle Question / Dcl_Id% Result acadfn fn fid)
- (if
- (and (or (setq fn (findfile "YesNo.dcl"))
- (setq acadfn (findfile "ACAD.PAT")
- fn (strcat (substr acadfn 1 (- (strlen acadfn) ) "YesNo.dcl")))
- (setq fid (open fn "w"))
- )
- ;; create dcl file in same directory as ACAD.PAT
- (progn
- (foreach x
- (list
- "YesNo : dialog { key = "Title";"
- " spacer;"
- (strcat " : text { key = "Question" ; width = "
- (itoa (+ (strlen Question) 4))
- " ; alignment = centered; }")
- " spacer;"
- " : row { fixed_width = true; alignment = centered;"
- " : button { key = "Yes"; label = "&Yes"; is_default = true;}"
- " : button { key = "No"; label = "&No"; is_cancel = true;}"
- " }"
- "}"
- )
- (princ x fid)
- (write-line "" fid)
- )
- (close fid)
- )
- )
- (cond
- ((setq Dcl_Id% (load_dialog fn))
- (new_dialog "YesNo" Dcl_Id%)
- (set_tile "Title" BoxTitle)
- (set_tile "Question" Question)
- (action_tile "Yes" "(done_dialog 1)")
- (action_tile "No" "(done_dialog 0)")
- (setq Result (start_dialog))
- (unload_dialog Dcl_Id%) ; Unload Dialog
- (if (and Result (= Result 1)) "Yes" "No")
- )
- (t nil)
- )
- )
|