Search code examples
dialoglispautocadmodeless

OPENDCL (AUTOCAD): avoid exiting modeless dialog if [ENTER] is pressed


I was looking for a way to avoid exiting modeless dialogs in autocad (created by opendcl) when [ENTER] is pressed.

Any idea?

Thanks, Dennis


Solution

  • I've implemented such a feature for the OpenDCL grid system. You have to activate the OnCancelClose function on your form. This is how I did it:

    (defun c:MyFunction_Form1_OnCancelClose (Reason /)
        ;; Reason = 0 when Enter is pressed
        (if (= Reason 0)
            (progn
                ;; Shift active editing cell one row down
                (setq rowAndCol(dcl_Grid_GetCurCell MyFunction_Form1_revisions))
                (dcl_Grid_StartCellEdit MyFunction_Form1_revisions (1+ (car rowAndCol)) (cadr rowAndCol))
            )
        )
    
        ;; Reason = 1 when ESC key is pressed, or the closing button in the titlebar
        ;; is clicked. Hence, enter won't work to cancel the dialog
        (/= Reason 1)
    )