My first odcl form

Started by s_plant, August 18, 2015, 06:36:15 AM

Previous topic - Next topic

s_plant

I read tutorial to create very simple form but does anyone know how can I call lisp routine within an loading odcl lisp? It makes me crazy, sometimes it working sometime not. I created very simple form and checked that and nothing is wrong. Here is my odcl lisp and my function lisp.

Function lisp:
Code (autolisp) Select
;;;;;;;;; Part of long lisp

(defun c:DELDIM (/ ss)
  (setq ss (ssget "x" (list (cons 0 "Dimension"))))
  (if ss
    (vl-cmdf ".erase" ss "")
    (princ "\nNo dimensions in this drawing!")
  )
  (princ)
)
;;;;;;;;;


and here is odcl lisp:


Code (autolisp) Select
(setq cmdecho (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (command "_OPENDCL")
  (setvar "CMDECHO" cmdecho)

(defun c:ddim ()
; call the method to load the deldim.odcl file.
(dcl_Project_Load "deldim" T)
(dcl_Form_Show deldim/Form1)
(princ)
)

(defun c:deldim/Form1/cmdDelDim#OnClicked (/)
(load "C:\\Lisps\\function.lsp")
(prompt "\function.lsp Loaded...")
  (c:DELDIM)
  (princ)
)

(defun c:deldim/Form1/cmdClose#OnClicked (/)
  (dcl-Form-Close deldim/Form1)
  (princ)
)


Thanks

owenwengerd

To execute commands in an event handler, you must ensure the control's Event Invoke property is set to Asynchronous so the event handler executes asynchronously.

s_plant

Thanks Owen. Can you please tell me which part I need to revisit?

owenwengerd

Design time properties can be changed in OpenDCL Studio. Open your .odcl file, open your form, select the button that triggers the event, then modify its Event Invoke property in the properties bar. I hope that helps.

Fred Tomke

Hi, s_plant, in addtion to Owens suggestions I recommend you to follow the FAQ about picking point from modal form. Sure, you don't want to pick a point, but they kind of code is quite similar: at the position of (getpoint) you have to put your deldim-command. Please also read the explanations in this FAQ: AutoCAD needs the control back at first before modifying the database. At the runtime of a modal form it has nach the control.

HTH, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Fred Tomke

Hi, please note that Owen's suggestions belongs to a palette, dockable and modeless form, my suggestion is related to a modal form. In modal forms there is no Event Invoke property, and you don't need to close a palette, dockable and modeless to call your deldim command. So, to give you the correct path, we need to know what type of form you've created.

HTH, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

s_plant

Please find attached all files. It screws with my head :o

s_plant


roy_043

Your files show a number of naming conflicts:

  • The close button has a different name in the .odcl file
  • The event names in the .odcl file don't match with the function names in the .lsp file.
  • The name of the additional .lsp file is 'functions.lsp' and not 'function.lsp'
Try to pay more attention to this. It will make your life as a programmer a lot easier if you do.

I have adapted your code following Fred's advice in post #4.
Code (autolisp) Select
(setvar "CMDECHO" 0)
(command "_OPENDCL")
(setvar "CMDECHO" 1)

(defun c:ddim (
                / c:deldim/Form1/cmdClose#OnClicked
                  c:deldim/Form1/cmdDelDim#OnClicked
                  c:deldim/Form1/cmdBDelDim#OnClicked
                  intResult
              )

  (defun c:deldim/Form1/cmdClose#OnClicked ()
    (dcl-Form-Close deldim/Form1 3)
  )

  (defun c:deldim/Form1/cmdDelDim#OnClicked ()
    (dcl-Form-Close deldim/Form1 4)
  )

  (defun c:deldim/Form1/cmdBDelDim#OnClicked ()
    (dcl-Form-Close deldim/Form1 5)
  )

  (setq intResult 100) ; Set intResult to 'big' dummy value.
  (dcl-Project-Load "deldim" T)
  (while (< 3 intResult) ; Keep (re)showing the dialog if intResult is 4 or 5.
    (setq intResult (dcl-Form-Show deldim/Form1))
    (cond
      ((= 4 intResult)
        (if (not c:DELDIM) (load "functions.lsp"))
        (c:DELDIM)
      )
      ((= 5 intResult)
        (if (not c:DELDIM) (load "functions.lsp"))
        (c:DELDIM)
      )
    )
  )
  (princ)
)

s_plant

Thanks Roy, You made my day  :D