Lisp 插件调用 .dcl 文件
Lisp Addin Call .dcl File
我正在尝试为 cad 插件学习和实现一些 lisp 代码,但我 运行 遇到了调用问题。我目前正在尝试为用户激活此插件时添加错误处理,但文件本身不在正确的目录中或文件未保存到某个位置。我遇到了一种方法,该方法允许我使用消息框向用户提问,但 lisp 文件并未提取 dcl 文件。应该如何解决这个错误?
范围:大图是用户点击功能区上的按钮或输入命令,所有文件都在与打开文件相同的文件夹中,活动绘图将收到修订更新。
应用程序: DraftSight 是添加 lisp 文件的地方。
原始教程:这是 the link 原始教程,我在其中找到了构建消息框的代码。
来自 DraftSight 的错误消息
我正在构建的代码:
;; 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
文件
// 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;}
}
}
////////////////////////////////////////////
我觉得问题在:
(setq dcl_id (load_dialog strcat(msgboxPath "\" "msgbox.dcl")))
应该在哪里:
(setq dcl_id (load_dialog ( strcat msgboxPath "\" "msgbox.dcl")))
我正在尝试为 cad 插件学习和实现一些 lisp 代码,但我 运行 遇到了调用问题。我目前正在尝试为用户激活此插件时添加错误处理,但文件本身不在正确的目录中或文件未保存到某个位置。我遇到了一种方法,该方法允许我使用消息框向用户提问,但 lisp 文件并未提取 dcl 文件。应该如何解决这个错误?
范围:大图是用户点击功能区上的按钮或输入命令,所有文件都在与打开文件相同的文件夹中,活动绘图将收到修订更新。
应用程序: DraftSight 是添加 lisp 文件的地方。
原始教程:这是 the link 原始教程,我在其中找到了构建消息框的代码。
来自 DraftSight 的错误消息
我正在构建的代码:
;; 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
文件
// 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;}
}
}
////////////////////////////////////////////
我觉得问题在:
(setq dcl_id (load_dialog strcat(msgboxPath "\" "msgbox.dcl")))
应该在哪里:
(setq dcl_id (load_dialog ( strcat msgboxPath "\" "msgbox.dcl")))