lisp addin call .dcl文件
我正在尝试学习并实施一些CAD Addin的LISP代码,但是我遇到了一个呼叫问题。我目前正在尝试为用户激活此addin时添加错误处理,但是文件本身不是位于正确的目录中,或者文件未保存到位置。我遇到了一种方法,该方法将使我可以用消息框向用户询问一个问题,但是LISP文件没有拉动DCL文件。该错误应该如何解决?
范围:大图是用户可以单击功能区上的按钮或键入命令,并且与打开的Active Drawd在同一文件夹中的所有文件都将接收修订更新。
应用程序:选秀是添加LISP文件的位置。
原始教程:这是链接到原始教程,我找到了用于构建消息框的代码。
来自草稿的错误消息
我正在构建的代码:
;; Global Constants
(defconstant msgboxPath "C:\\Users\\GarrettB\\Documents\\Visual Studio Code\\DraftSight LISP")
;;
(defun C:ProjectRev()
;; Pulls the directory from the active file
(setq dirPath (vl-catch-all-apply getvar 'dwgprefix))
;; Checks for an error
(if not (vl-catch-all-error-p dirPath)
(progn ; No error - Ask user if this is the right path
(setq UserRespond (lspYesNoCancel "Is this the correct path?" dirfile "" "PROJECT REVISION"))
(princ (type UserRespond))
(princ UserRespond)
;; if yes then continue
;; else ask for correct directory (function call)
;; (setq dirPath (browseForFolder "Select the project folder: " 1 "d:\\"))
);progn
(progn ; Error - File is not saved to a directory
;; ask for correct directory (function call)
;; (setq dirPath (browseForFolder "Select the project folder: " 1 "d:\\"))
);progn
);if
;; WORK IN PROGRESS
;; Gather drawings into a list
;; Copy drawings and place into "Past revisions" folder
;; Add revision to drawings
;; Modify drawing's names
;; Save, close, and end
)
;; Source: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-on-all-dwg-directory/td-p/6214507
;; Browses the current directory for .dwg files
(defun browseForFolder (title options rootFolder / sh folder folderobject result)
(vl-load-com)
(setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application")) ; sets the Shell Terminal variable
;; Obtaining starting location
(setq folder (vlax-invoke-method sh 'BrowseForFolder
(vla-get-hwnd (vlax-get-acad-object)) title options rootFolder)) ; User sets the folder path and file name as an object?
(vlax-release-object sh) ;-------------------------------------------; Releases the shell application object
(setq sh nil) ;------------------------------------------------------; Sets the sh variable to nothing
; If folder is not nil
(if folder
(progn
;; Conversion
(setq folderobject (vlax-get-property folder 'Self)) ; Sets the folder path as an object
(setq result (vlax-get-property FolderObject 'Path)) ; Sets the folder path as a string
;; Release and nullify
(vlax-release-object folder) ;-----; Releases the folder path and file name as an object?
(vlax-release-object FolderObject) ; Releases the folder path as a string
(setq folder nil) ;----------------; Sets the folder variable to nothing
(setq FolderObject nil) ;----------; Sets the FolderObject variable to nothing
;; Returning variable
result
); progn
); if
); defun browserForFolder
;; Source: https://www.afralisp.net/dialog-control-language/tutorials/the-autolisp-message-box.php
;; Lisp code from tutorial
(defun lspYesNoCancel (message1 message2 message3 main)
;; Creating dialoge box
(setq dcl_id (load_dialog strcat(msgboxPath "\\" "msgbox.dcl")))
;; Error prevention
(if (not (new_dialog "lspYesNoCancel" dcl_id)) (exit))
;; Dialoge Message
(set_tile "message1" message1)
(set_tile "message2" message2)
(set_tile "message3" message3)
(set_tile "main" main)
;; Command Buttons
(action_tile "no" "(done_dialog) (setq result \"F\")")
(action_tile "yes" "(done_dialog) (setq result T)")
(action_tile "cancel" "(done_dialog) (setq result nil)")
;; Interaction
(start_dialog) ; Show dialog box
(unload_dialog dcl_id) ; Close dialoge box
(princ)
)
这是msgbox.dcl
file
// Source: https://www.afralisp.net/dialog-control-language/tutorials/the-autolisp-message-box.php
////////////////////////////////////////////////
lspOkCancel : dialog {
key = "main";
: column {
: text {key = "message1";}
: text {key = "message2";}
: text {key = "message3";}
}
: row {
: spacer {width = 1;}
: button {
label = "OK";
key = "accept";
width = 12;
fixed_width = true;
mnemonic = "O";
is_default = true;
}
: button {
label = "Cancel";
key = "cancel";
width = 12;
fixed_width = true;
mnemonic = "C";
is_cancel = true;
}
: spacer { width = 1;}
}
}
////////////////////////////////////////////////
lspYesNo : dialog {
key = "main";
: column {
: text {key = "message1";}
: text {key = "message2";}
: text {key = "message3";}
}
: row {
: spacer {width = 1;}
: button {
label = "Yes";
key = "yes";
width = 12;
fixed_width = true;
mnemonic = "Y";
is_default = true;
}
: button {
label = "No";
key = "no";
width = 12;
fixed_width = true;
mnemonic = "N";
is_cancel = true;
}
: spacer { width = 1;}
}
}
////////////////////////////////////////////
lspOkOnly : dialog {
key = "main";
: column {
: text {key = "message1";}
: text {key = "message2";}
: text {key = "message3";}
}
: row {
: spacer { width = 1; }
: button {
label = "OK";
key = "accept";
width = 12;
fixed_width = true;
mnemonic = "O";
is_default = true;
alignment = centered;
}
: spacer { width = 1;}
}
}
////////////////////////////////////////////////
lspYesNoCancel : dialog {
key = "main";
: column {
: text {Key = "message1";}
: text {key = "message2";}
: text {key = "message3";}
}
: row {
: spacer {width = 1;}
: button {
label = "Yes";
key = "yes";
width = 12;
fixed_width = true;
mnemonic = "Y";
is_default = true;
}
: button {
label = "No";
key = "no";
width = 12;
fixed_width = true;
mnemonic = "N";
}
: button {
label = "Cancel";
key = "cancel";
width = 12;
fixed_width = true;
mnemonic = "C";
is_cancel = true;
}
: spacer {width = 1;}
}
}
////////////////////////////////////////////
lspRentryCancel : dialog {
key = "main";
: column {
: text {key = "message1";}
: text {key = "message2";}
: text {key = "message3";}
}
: row {
: spacer { width = 1; }
: button {
label = "Rentry";
key = "rentry";
width = 12;
fixed_width = true;
mnemonic = "R";
is_default = true;
}
: button {
label = "Cancel";
key = "Cancel";
width = 12;
fixed_width = true;
mnemonic = "C";
is_cancel = true;
}
: spacer {width = 1;}
}
}
////////////////////////////////////////////
I'm trying to both learn and implement some lisp code for a cad addin, but I'm running into a calling issue. I'm currently trying to add an error handling for when the user activates this addin, but the file itself is either not located in the correct directory or the file is not saved to a location. I came across a method that will allow me to ask the user a question with a message box, but the lisp file isn't pulling the dcl file. How should this error be resolved?
Scope: The big picture is for the user to either click a button on the ribbon or by typing a command, and all of the files in the same folder as the open, active drawing will receive a revision update.
Application: DraftSight is where the lisp file is being added.
Original Tutorial: Here's the link to the original tutorial where I found the code to build the message box.
Error Message from DraftSight
Code I'm building:
;; Global Constants
(defconstant msgboxPath "C:\\Users\\GarrettB\\Documents\\Visual Studio Code\\DraftSight LISP")
;;
(defun C:ProjectRev()
;; Pulls the directory from the active file
(setq dirPath (vl-catch-all-apply getvar 'dwgprefix))
;; Checks for an error
(if not (vl-catch-all-error-p dirPath)
(progn ; No error - Ask user if this is the right path
(setq UserRespond (lspYesNoCancel "Is this the correct path?" dirfile "" "PROJECT REVISION"))
(princ (type UserRespond))
(princ UserRespond)
;; if yes then continue
;; else ask for correct directory (function call)
;; (setq dirPath (browseForFolder "Select the project folder: " 1 "d:\\"))
);progn
(progn ; Error - File is not saved to a directory
;; ask for correct directory (function call)
;; (setq dirPath (browseForFolder "Select the project folder: " 1 "d:\\"))
);progn
);if
;; WORK IN PROGRESS
;; Gather drawings into a list
;; Copy drawings and place into "Past revisions" folder
;; Add revision to drawings
;; Modify drawing's names
;; Save, close, and end
)
;; Source: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-on-all-dwg-directory/td-p/6214507
;; Browses the current directory for .dwg files
(defun browseForFolder (title options rootFolder / sh folder folderobject result)
(vl-load-com)
(setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application")) ; sets the Shell Terminal variable
;; Obtaining starting location
(setq folder (vlax-invoke-method sh 'BrowseForFolder
(vla-get-hwnd (vlax-get-acad-object)) title options rootFolder)) ; User sets the folder path and file name as an object?
(vlax-release-object sh) ;-------------------------------------------; Releases the shell application object
(setq sh nil) ;------------------------------------------------------; Sets the sh variable to nothing
; If folder is not nil
(if folder
(progn
;; Conversion
(setq folderobject (vlax-get-property folder 'Self)) ; Sets the folder path as an object
(setq result (vlax-get-property FolderObject 'Path)) ; Sets the folder path as a string
;; Release and nullify
(vlax-release-object folder) ;-----; Releases the folder path and file name as an object?
(vlax-release-object FolderObject) ; Releases the folder path as a string
(setq folder nil) ;----------------; Sets the folder variable to nothing
(setq FolderObject nil) ;----------; Sets the FolderObject variable to nothing
;; Returning variable
result
); progn
); if
); defun browserForFolder
;; Source: https://www.afralisp.net/dialog-control-language/tutorials/the-autolisp-message-box.php
;; Lisp code from tutorial
(defun lspYesNoCancel (message1 message2 message3 main)
;; Creating dialoge box
(setq dcl_id (load_dialog strcat(msgboxPath "\\" "msgbox.dcl")))
;; Error prevention
(if (not (new_dialog "lspYesNoCancel" dcl_id)) (exit))
;; Dialoge Message
(set_tile "message1" message1)
(set_tile "message2" message2)
(set_tile "message3" message3)
(set_tile "main" main)
;; Command Buttons
(action_tile "no" "(done_dialog) (setq result \"F\")")
(action_tile "yes" "(done_dialog) (setq result T)")
(action_tile "cancel" "(done_dialog) (setq result nil)")
;; Interaction
(start_dialog) ; Show dialog box
(unload_dialog dcl_id) ; Close dialoge box
(princ)
)
Here's the msgbox.dcl
file
// Source: https://www.afralisp.net/dialog-control-language/tutorials/the-autolisp-message-box.php
////////////////////////////////////////////////
lspOkCancel : dialog {
key = "main";
: column {
: text {key = "message1";}
: text {key = "message2";}
: text {key = "message3";}
}
: row {
: spacer {width = 1;}
: button {
label = "OK";
key = "accept";
width = 12;
fixed_width = true;
mnemonic = "O";
is_default = true;
}
: button {
label = "Cancel";
key = "cancel";
width = 12;
fixed_width = true;
mnemonic = "C";
is_cancel = true;
}
: spacer { width = 1;}
}
}
////////////////////////////////////////////////
lspYesNo : dialog {
key = "main";
: column {
: text {key = "message1";}
: text {key = "message2";}
: text {key = "message3";}
}
: row {
: spacer {width = 1;}
: button {
label = "Yes";
key = "yes";
width = 12;
fixed_width = true;
mnemonic = "Y";
is_default = true;
}
: button {
label = "No";
key = "no";
width = 12;
fixed_width = true;
mnemonic = "N";
is_cancel = true;
}
: spacer { width = 1;}
}
}
////////////////////////////////////////////
lspOkOnly : dialog {
key = "main";
: column {
: text {key = "message1";}
: text {key = "message2";}
: text {key = "message3";}
}
: row {
: spacer { width = 1; }
: button {
label = "OK";
key = "accept";
width = 12;
fixed_width = true;
mnemonic = "O";
is_default = true;
alignment = centered;
}
: spacer { width = 1;}
}
}
////////////////////////////////////////////////
lspYesNoCancel : dialog {
key = "main";
: column {
: text {Key = "message1";}
: text {key = "message2";}
: text {key = "message3";}
}
: row {
: spacer {width = 1;}
: button {
label = "Yes";
key = "yes";
width = 12;
fixed_width = true;
mnemonic = "Y";
is_default = true;
}
: button {
label = "No";
key = "no";
width = 12;
fixed_width = true;
mnemonic = "N";
}
: button {
label = "Cancel";
key = "cancel";
width = 12;
fixed_width = true;
mnemonic = "C";
is_cancel = true;
}
: spacer {width = 1;}
}
}
////////////////////////////////////////////
lspRentryCancel : dialog {
key = "main";
: column {
: text {key = "message1";}
: text {key = "message2";}
: text {key = "message3";}
}
: row {
: spacer { width = 1; }
: button {
label = "Rentry";
key = "rentry";
width = 12;
fixed_width = true;
mnemonic = "R";
is_default = true;
}
: button {
label = "Cancel";
key = "Cancel";
width = 12;
fixed_width = true;
mnemonic = "C";
is_cancel = true;
}
: spacer {width = 1;}
}
}
////////////////////////////////////////////
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题是一致的:
应该在哪里:
I think the problem is in line:
Where should be rather: