Remembering Dialog Position

This tutorial demonstrates how to 'remember' the position of a DCL dialog so that it may appear in that position the next time the program is used.

This tutorial assumes the reader knows how to work with DCL using LISP to a basic level.

The example code shown below uses a global variable (namely *screenpoint*) to store the position of the dialog. This data is stored as a 2D list representing the position of the dialog on the screen. Alternatively, the positional data could be converted to a string and stored in the registry to remember the dialog position between drawing sessions.

To better understand how this screen coordinate is used to position the dialog, refer to the VLIDE Help Documentation on the new_dialog & done_dialog functions - see here if you are unsure how to find this information.

The Code

DCL File

Save this code in an AutoCAD Support Path as: test.dcl

Select all
// DCL File to be saved as test.dcl
// Example courtesy of Lee Mac  2011 (www.lee-mac.com)

test : dialog { label = "Test Dialog";
  spacer;
  : text { label = "Move me"; alignment = centered; }
  spacer;
  : button { key = "accept"; is_default = true; label = "I'm Done"; }
}

LISP File

This may be saved using an arbitrary filename, for loading instructions see How to Run an AutoLISP Program.

When loaded, start the program using test at the command line.

Select all
(defun c:test ( / *error* dcl dch )

  ;; Example by Lee Mac 2011  -  www.lee-mac.com
  
  ;; Demonstrates how to remember a dialog screen
  ;; position for next use.

  ;; Requires accompanying file: test.dcl to be
  ;; saved in an AutoCAD Support Path.


  ;; Error Handler so that we may unload the dialog
  ;; from memory should the user hit Esc.

  (defun *error* ( msg )
    (if dch (unload_dialog dch))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ)
  )

  ;; Plentiful Error trapping to make sure
  ;; dialog is loaded successfully.

  (cond
    (
      (not
        (and
          (setq dcl (findfile "test.dcl"))    ;; Check for DCL file
          (< 0 (setq dch (load_dialog dcl)))  ;; Attempt to load it if found
        )
      )

      ;; Else dialog is either not found or couldn't be loaded:

      (princ "\n** DCL File not found **")
    )
    (
      (not (new_dialog "test" dch "" (cond ( *screenpoint* ) ( '(-1 -1) ))))

      ;; If our global variable *screenpoint* has a value it will be
      ;; used to position the dialog, else the default (-1 -1) will be
      ;; used to center the dialog on screen.

      ;; Should the dialog definition not exist, we unload the dialog
      ;; file from memory and inform the user:
                                             
      (setq dch (unload_dialog dch))
      (princ "\n** Dialog could not be Loaded **")
    )
    (t

      ;; Dialog loaded successfully, now we define the action_tile
      ;; statements:
     
      (action_tile "accept" "(setq *screenpoint* (done_dialog 1))")

      ;; The dialog screen position is returned by the done_dialog
      ;; function, so we store this in our global variable *screenpoint*
      ;; for next time.

      (start_dialog)

      ;; Display the dialog - we can use the return of start_dialog
      ;; to determine whether the user pressed OK or Cancel.

      (setq dch (unload_dialog dch))

      ;; We're done, unload the Dialog from memory.
    )
  )

  (princ) ;; Exit Quietly...
)

Result

Dialog Position.gif

textsize

increase · reset · decrease

Designed & Created by Lee Mac © 2010