首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Lisp Addin调用.dcl文件

Lisp Addin调用.dcl文件
EN

Stack Overflow用户
提问于 2022-04-28 22:53:08
回答 1查看 158关注 0票数 1

我正在努力学习和实现cad加载项的一些lisp代码,但我遇到了一个调用问题。我目前正在尝试添加一个错误处理,以便当用户激活这个加载项时,但是文件本身不是位于正确的目录中,就是文件没有保存到某个位置。我遇到了一种方法,它允许我用消息框询问用户一个问题,但是lisp文件并没有拉出dcl文件。如何解决此错误?

范围:大图片是用户单击带状上的按钮或键入命令,与打开的活动绘图所在的文件夹中的所有文件都将收到修订更新。

应用程序: DraftSight是添加lisp文件的地方。

原始教程:这里是原始教程的链接,在这里我找到了构建消息框的代码。

来自DraftSight的错误消息

我正在建造的代码:

代码语言:javascript
复制
;; 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文件

代码语言:javascript
复制
// 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;}
    }
}
 
////////////////////////////////////////////
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-29 03:22:28

我认为问题是一致的:

代码语言:javascript
复制
(setq dcl_id (load_dialog strcat(msgboxPath "\\" "msgbox.dcl")))

应该在哪里:

代码语言:javascript
复制
(setq dcl_id (load_dialog ( strcat msgboxPath "\\" "msgbox.dcl")))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72051040

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档