An OpenDCL application consists of AutoLISP code and OpenDCL project data. The OpenDCL project data is created and edited in OpenDCL Studio, and can exist either as a separate .odcl file or as data within the AutoLISP code. Embedding the project data within the AutoLISP code is an advanced topic that is covered elsewhere.
OpenDCL uses an event driven programming model, where user interface events trigger calls to event handlers that perform the work of the application. A typical OpenDCL application includes code to load and display a form, along with event handlers that manage the form once it is displayed. Event handlers respond to user actions such as pressing a button or selecting an item in a list.
The AutoLISP code that displays an OpenDCL form must first ensure that the OpenDCL Runtime module is loaded. This is done by utilizing AutoCAD's demand loading feature by executing the OPENDCL command. There is no need to check whether the runtime is already loaded -- if it is, the command does nothing.
(command "_OPENDCL")
The next step is to load the project data. If the project data is stored in a file, it can be loaded by calling the (dcl-Project-Load) function. If you choose to embed the project data within the AutoLISP code, it can be loaded by calling the (dcl-Project-Import) function.
Once the project data is loaded, a call to (dcl-Form-Show) will create a dialog and display it on the screen. After the dialog is displayed, AutoLISP event handlers take over and manage the form until it is closed. Initializing the dialog must be done in an event handler called OnInitialize. Following is typical code for displaying a simple modal dialog:
(defun C:MyCommand (/ Result) (command "_OPENDCL") ; Load OpenDCL Runtime (if (dcl-Project-Load "MyProject") ; Load project data from MyProject.odcl (progn (setq Result (dcl-Form-Show MyProject/MyForm)) ; Note that this code does not execute until *after* the dialog is closed! (if (= Result 1) (DoSomething)) ) ) (princ) )(defun c:MyProject/MyForm#OnInitialize (/) (dcl-Control-SetCaption MyProject/MyForm/Label1 "Hello World!") )(defun c:MyProject/MyForm/CloseButton#OnClicked (/) (dcl-Form-Close MyProject/MyForm) )
As you can see, the code for displaying the dialog is very simple. The work of initializing, managing, and responding to the dialog events all happens in separate event handlers that get called while the dialog is active. The dialog is closed when an event handler calls (dcl-Form-Close). Note that (dcl-Form-Close) can be given an optional dialog status code that is subsequently returned by the (dcl-Form-Show) function. This status code can be used to determine what, if anything, should be done after the dialog has closed.