BIGAL 发表于 2022-7-5 18:07:09

我很快就会发布一个getval。dcl不工作,您在lisp中提供标题、方框宽度等,它返回一个值,我将其用作全局请求定义。对于我编写的任何lisp,请按任意键选择“是”,除非这是“否”。
 
优点是调用lisp只有3行,所有加载的dcl代码都在Getval中。lsp使编写新的lisp变得更容易

DanW 发表于 2022-7-5 18:09:42

这是另一种剥猫皮的方法。如果按yes,则返回T:
 
(defun IS_YES_PRESSED? (title message / vlaobj result)
(vl-load-com)
(vl-catch-all-apply
   (function
   (lambda ()
       (setq vlaobj (vlax-create-object "WScript.Shell"))
       (setq result (vlax-invoke-method vlaobj 'popup message 0 title 4132))
   )
   )
)
(if vlaobj (vlax-release-object vlaobj))
(= result 6)
)


;(IS_YES_PRESSED? "My dialogue" "Please choose ....")

GP_ 发表于 2022-7-5 18:12:26

 
 
 
 
相像的
 

DanW 发表于 2022-7-5 18:17:59

有趣的如果我知道这是在李的优秀网站上,我会把它链接起来。
 
实际上,lisp是从Bricscad的免费vle扩展中改编而来的。lsp。道歉可能应该归功于此。

Lee Mac 发表于 2022-7-5 18:18:04

 
谢谢你的赞美丹;虽然发现“vle extension.lsp”中的这样一个函数与我网站上发布的函数非常相似,这很有趣,但我意识到代码只有几行,但布局似乎几乎相同。很遗憾,我没有访问vle扩展的权限。lsp,但我有兴趣看一下。

BIGAL 发表于 2022-7-5 18:22:37

另一个例子
 

;calling code plus return answer
(setq title "Please enter dwg number")
(setq width "   edit_width = 15;")
(setq limit "   edit_limit = 12;")
(ah:getval title)
(setq dwgname item)


;; InputDialog box with variable title
;; By Ah June 2012 thanks to AlanJT for source idea
;; code (ah:getval title)
(defun AH:Getval (title width limit / fo)
(setq fname "C://acadtemp//getval.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) "sizze" (chr 34) ";") fo)
(write-line(strcat " label = "(chr 34) title (chr 34) ";")   fo)
; these can be replaced with shorter value etc
;(write-line "   edit_width = 18;" fo)
;(write-line "   edit_limit = 15;" fo)
(write-line width fo)
(write-line limit fo)
(write-line "   is_enabled = true;" fo)      
(write-line "    }" fo)
(write-line "}" fo)
(write-line "ok_cancel;}" fo)
(close fo)
(setq dcl_id (load_dialog"c:\\acadtemp\\getval"))
(if (not (new_dialog "ddgetval" dcl_id))
(exit))
(action_tile "sizze" "(setq item$value)(done_dialog)")
(mode_tile "sizze" 3)
(start_dialog)
; returns the value of item
)



mrc1986 发表于 2022-7-5 18:26:40

我是这个论坛的新手,我知道这是一个旧线程,但我试图使用CAB发布的代码,顺便说一句,很棒,所以如果我需要启动一个新线程,我可以。
我正在尝试使用消息框,并使用IF语句触发事件,具体取决于它们是否单击Yes或No。我一定错过了什么,因为我无法使用IF语句来解释单击Yes或No。
 
最后,当用户关闭时,它会要求用户清除和审核图形(我已经有了所有编码,只需要Msgbox),所以我只使用了两个不同的命令来判断它是否正常工作。你们能告诉我我错过了什么吗。
 
谢谢

;; 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)
)
)

(IF (yesno "Purg audit""message goes here") = yes)
(command "line")
(command "circle")
)

mrc1986 发表于 2022-7-5 18:28:31

只是我的头还不够猛。。。错误地使用了if语句。

(setq reply (yesno "Purg audit""message goes here"))

(IF (= replyyes)
(command "line")
(command "circle")
)

pkenewell 发表于 2022-7-5 18:32:27

 
 
if语句中的YES必须是字符串并与大小写匹配。您还需要完成命令语句:

(if (= reply "Yes")
(command "line" pause pause "")
(command "Circle" Pause Pause)
)

mrc1986 发表于 2022-7-5 18:34:44

谢谢你的“是”让我们有点不同。我对更深入的Lisp函数有点陌生。
我还添加了一个检查,看看它是否是一个全新的图纸,尚未保存,否则它试图保存文件随机。我相信我们会将其添加到我们的acad2014doc中。Lisp文件,以创建一种方法,确保人们正在审核和清除图形。
最后的Lisp程序最终变成了这样:

;; 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)
)
)
(vl-load-com)
(defun Create_Close_Reactor()
(if(not close:reactor)
   (setq close:reactor
(vlr-editor-reactor nil
    '((:vlr-beginClose . CloseReaction))))
   ); end if
(princ)
); end of Create_Close_Reactor

(defun CloseReaction(args reac / actDoc)
(if (zerop (getvar 'dwgtitled))
   (null)
(progn
(setq reply (yesno "Closing" "Would you like to Audit and Purge your Drawing"))
(IF (= reply "Yes")
   (progn
   (setq actDoc(vla-get-ActiveDocument
   (vlax-get-acad-object)))
   (vla-ZoomExtents(vlax-get-acad-object))
   (vla-AuditInfo (vla-get-ActiveDocument (vlax-get-object "AutoCAD.Application")) :Vlax-True)
   (repeat 3(vla-PurgeAll actDoc))
   (vla-Save actDoc)
   )
(progon
(setq actDoc(vla-get-ActiveDocument
(vlax-get-acad-object)))
(vla-ZoomExtents(vlax-get-acad-object))
(vla-Save actDoc)
)
)
)
)
(princ)
); end of CloseReaction
(Create_Close_Reactor)
页: 1 [2]
查看完整版本: 是否消息