You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AutoLisp-DCL对话框为何需OK/CANCEL按钮?如何移除冗余按钮?

问题描述

我在为DraftSight开发更新标题栏和版本信息的对话框时遇到报错,继续操作会导致程序崩溃。添加ok_cancel ;后崩溃停止,但出现了冗余的无明确功能的按钮。请问如何在不添加额外按钮的情况下让对话框正常运行?

Lisp代码

(setq *sDCLPath* "[Stored directory]"); Either use "\\" or "/" between folder names
(setq *sName01* "[File's name]")

;; Starts the dialog box for user input
(defun C:Test01 (/ sPathAndName dclFile vModule)

    ;; File Exists
    (setq sPathAndName (findfile (strcat *sDCLPath* "\\" *sName01* ".dcl")))
    (if (not sPathAndName)(progn 
        (princ "\nError: The DCL file was not found.\n")
        (princ "\nPath and name: ")(princ sPathAndName)(terpri)
        (exit)
    ));if<-progn
    
    ;;  DCL File
    (setq dclFile (load_dialog sPathAndName))
    (if (>= 0 dclFile)(progn 
        (princ "\nError: DCL file cannot be loaded.\n")
        (exit)
    ));if<-progn
    
    (new_dialog "TitleRevUpdate" dclFile "(done_dialog 0)" '(-1 -1))
    (start_dialog)
    (unload_dialog dclFile)
    (gc)
    (princ)
);C:Test01

DCL代码

TitleRevUpdate : dialog {
    key = "Title" ;
    label = "Update Title Block and Revision" ;
    
    // Title
    : boxed_column {
        key = "Column_TitleBoxes" ;
        label = "Title" ;
        
        // Client
        : boxed_column {
            key = "Client_Box" ;
            label = "Client" ;
            : row { // Row 01 - Name
                key = "Row_Client_Name" ;
                : text {
                    key = "txt_Client_Name" ;
                    label = "Client's Name" ;
                }// text
                : edit_box {
                    key = "edbx_Client_Name" ;
                }// edit_box
            } //row
            : row { // Row 02 - Location
                key = "Row_Client_Loc" ;
                : text {
                    key = "txt_Client_Loc" ;
                    label = "Client's Location" ;
                }// text
                : edit_box {
                    key = "edbx_Client_Loc" ;
                }// edit_box
            } //row
        } //boxed_column
        : spacer ;
        
        // Job
        : boxed_column {
            key = "Job_Box" ;
            label = "Job" ;
            : row { // Row 03 - Name
                key = "Row_Job_Name" ;
                : text {
                    key = "txt_Job_Name" ;
                    label = "Job's Name" ;
                }// text
                : edit_box {
                    key = "edbx_Job_Name" ;
                }// edit_box
            } //row
            : row { // Row 04 - Number
                key = "Row_Job_Number" ;
                : text {
                    key = "txt_Job_Number" ;
                    label = "Job's Number" ;
                }// text
                : edit_box {
                    key = "edbx_Job_Number" ;
                }// edit_box
            } //row
        } //boxed_column
        : spacer ;
        
        // Miscellaneous
        : boxed_column {
            key = "Miscellaneous_Box" ;
            label = "Miscellaneous" ;
            : row { // Row 05 - Creator's Initials
                key = "Row_Creator_Name" ;
                : text {
                    key = "txt_Creator_Name" ;
                    label = "Creator's Name" ;
                }// text
                : edit_box {
                    key = "edbx_Creator_Name" ;
                }// edit_box
            } //row
            : row { // Row 06 - Date of Creation
                key = "Row_Date" ;
                : text {
                    key = "txt_TitleDate" ;
                    label = "Date" ;
                }// text
                : edit_box {
                    key = "edbx_TitleDate" ;
                }// edit_box
            } //row
            : row { // Row 07 - Issued For
                key = "Row_Issued_For" ;
                : text {
                    key = "txt_Issued_For" ;
                    label = "Issued For" ;
                }// text
                : edit_box {
                    key = "edbx_Issued_For" ;
                }// edit_box
            } //row
        } //boxed_column
    } //boxed_column
    : spacer ;
    
    // Revision
    : boxed_column {
        key = "Column_Revision" ;
        label = "Revision" ;
        : row { // Row 08 - Quick Choices
            key = "Row_Buttons" ;
            : button {
                key = "btn_IFC" ;
                label = "Issued for Construction" ;
            }// button
            : button {
                key = "tbn_AB" ;
                label = "As Built" ;
            }// button
            : radio_column {
                key = "RadioCol_WriteMethod" ;
                : radio_button {
                    key = "rbtn_Owt" ;
                    label = "Clear & Overwrite" ;
                }// radio_button
                : radio_button {
                    key = "rbtn_Apnd" ;
                    label = "Append / New Line" ;
                }// radio_button
            } //radio_column
        } //row
        : spacer ;
        : row { // Row 09 - Rev Labels
            key = "Row_Labels" ;
            : text {
                key = "txt_Rev" ;
                label = "Rev" ;
            }// text
            : text {
                key = "txt_Initials" ;
                label = "Initials" ;
            }// text
            : text {
                key = "txt_Description" ;
                label = "Description" ;
            }// text
            : text {
                key = "txt_RevDate" ;
                label = "Date" ;
            }// text
        } //row
        : row { // Row 10 - Rev Edit Boxes
            key = "Row_Rev" ;
            : edit_box {
                key = "edbx_Rev" ;
            }// edit_box
            : edit_box {
                key = "edbx_Initials" ;
            }// edit_box
            : edit_box {
                key = "edbx_Date" ;
            }// edit_box
            : edit_box {
                key = "edbx_RevDate" ;
            }// edit_box
        } //row
    } //boxed_column
    : spacer ;
    
    // Return Commands
    : row { // Row 11 - Buttons
        key = "Row_Return" ;
        : button {
            key = "btn_DWGs" ;
            action = "(done_dialog 2)" ;
            label = "Show Drawings" ;
        }// button
        : button {
            key = "btn_Confirm" ;
            action = "(done_dialog 1)" ;
            label = "Confirm" ;
        }// button
        : button {
            key = "btn_Cancel" ;
            action = "(done_dialog 0)" ;
            label = "Cancel" ;
        }// button
    } //row
    ok_cancel ; // How to remove this without throwing errors.
    : spacer ;
} // TitleRevUpdate

解决方案

问题根源

崩溃是因为DCL对话框缺少默认的关闭逻辑,ok_cancel是DCL预定义的控件集合,会自动添加确定/取消按钮并绑定基础关闭逻辑,但这和你自定义的按钮功能重复,导致出现冗余控件。

具体修复步骤

  1. 删除DCL中的冗余代码
    直接移除DCL代码末尾的ok_cancel ; // How to remove this without throwing errors.这一行,避免生成多余按钮。

  2. 补全未绑定逻辑的按钮
    你自定义的btn_IFC和tbn_AB按钮目前没有绑定action,用户点击后会无响应,建议补充功能逻辑(比如填充默认值):

    : button {
        key = "btn_IFC" ;
        label = "Issued for Construction" ;
        action = "(set_tile \"edbx_Issued_For\" \"Issued for Construction\")" ;
    }// button
    : button {
        key = "tbn_AB" ;
        label = "As Built" ;
        action = "(set_tile \"edbx_Issued_For\" \"As Built\")" ;
    }// button
    
  3. 优化Lisp初始化逻辑
    可以在对话框初始化时添加默认值设置,提升用户体验,同时确保关闭逻辑完整:

    (new_dialog "TitleRevUpdate" dclFile "(done_dialog 0)" '(-1 -1))
    ; 设置默认日期为当前系统日期
    (set_tile "edbx_TitleDate" (rtos (getvar "cdate") 2 0))
    (set_tile "edbx_RevDate" (rtos (getvar "cdate") 2 0))
    ; 默认选中"Clear & Overwrite"单选按钮
    (set_tile "rbtn_Owt" "1")
    (start_dialog)
    

验证效果

修改完成后,对话框只会显示你自定义的Show Drawings、Confirm、Cancel三个按钮,点击任意按钮都会通过done_dialog正常关闭对话框,不会再出现崩溃或冗余按钮问题。

内容的提问来源于stack exchange,提问作者G Beck

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 13:05:30