Author Topic: Help tying lisp to buttons and check boxes  (Read 375 times)

CADworker

  • Member
  • *
  • Posts: 6
Help tying lisp to buttons and check boxes
« on: July 29, 2021, 01:44:49 PM »
I'm new to OpenDcl, I've been told it would be easier to write DCL code here from Mr. Darren Young from XtraCAD. So far I've been able to at least get a dialog to come up and close, Yea! I'm to the point where I'm not sure how to get my functions to work. I would like to be able to check a box or two, depending on what options I need, and then push the button "Collaborate" to run my lisp and run the routines that were checked.
I would also like to be able to use the "Save" button to save my drawing before running this routine.

Any help would be appreciated, thanks!

See attached screen shot of dialog.
My lisp code:
Code: [Select]


(command "OPENDCL") ;;;Ensure the appropriate OpenDCL ARX file is loaded

(defun c:Collab ()
   (dcl_Project_Load "Collab" T) ;;;call the method to load the Collab.odcl file. 
   (dcl_Form_Show Collab_PopUp) ;;;call the method to show the Collab dialog box example
   (princ)
)
;;;set values of labels
(defun c:Collab/PopUp#OnInitialize (/)
  (dcl-Control-SetCaption Collab/PopUp/Label1 "Do you wish to SAVE before changes?")
  (dcl-Control-SetCaption Collab/PopUp/Label2 "Set UCS to world")
  (dcl-Control-SetCaption Collab/PopUp/Label3 "Detach XRef's")
  (dcl-Control-SetCaption Collab/PopUp/Label4 "One Viewport at PlanView")
)

;;;set button parameters
(defun c:Collab/PopUp/CloseButton#OnClicked (/)
  (dcl-Form-Close Collab/PopUp)
)

;;;set check box parameters
(defun c:Collab/Form1/CheckBox1#OnClicked (nValue /)
  (if (= nValue 0)
    (dcl_Control_SetEnabled Collab_PopUp_Form1 nil)
;;;    (dcl_Control_SetEnabled Collab_PopUp_Form1 T)
)
)

Fred Tomke

  • OpenDCL Technician
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2070
  • [ Mr. Bad Guy ]
    • Kommunale Entwicklungsplanung auf digitaler Basis - digital landscape and urban design
Re: Help tying lisp to buttons and check boxes
« Reply #1 on: July 30, 2021, 12:32:40 AM »
Hi, please have a look at the OpenDCL samples at C:\Program Files (x86)\OpenDCL Studio\<your_language>\Samples.
I've modified your code a bit. Please note that I do not know the names of the checkboxes. So handle it as dummy code only.

Code: [Select]
(defun c:Collab (/ c:Collab/PopUp#OnInitialize
   c:Collab/PopUp/Checkbox1#OnClicked
   c:Collab/PopUp/Checkbox1#OnClicked
   c:Collab/PopUp/Checkbox1#OnClicked
   nValue1 nValue2 nValue3)
 
  (if (not dcl_Project_Load) (command "OPENDCL")) ;;;Ensure the appropriate OpenDCL ARX file is loaded
  (dcl_Project_Load "Collab" T) ;;;call the method to load the Collab.odcl file.

  ;;; Sample code to get values
  (setq nValue1 (getvar "USERI1"))
  (setq nValue2 (getvar "USERI2"))
  (setq nValue3 (getvar "USERI3"))

  ;;;set values of labels
  (defun c:Collab/PopUp#OnInitialize (/)
    (dcl-Control-SetCaption Collab/PopUp/Label1 "Do you wish to SAVE before changes?")
    (dcl-Control-SetCaption Collab/PopUp/Label2 "Set UCS to world")
    (dcl-Control-SetCaption Collab/PopUp/Label3 "Detach XRef's")
    (dcl-Control-SetCaption Collab/PopUp/Label4 "One Viewport at PlanView")

   ;; set values
    (dcl-Control-SetValue Collab/PopUp/Checkbox1 nValue1)
    (dcl-Control-SetValue Collab/PopUp/Checkbox2 nValue2)
    (dcl-Control-SetValue Collab/PopUp/Checkbox3 nValue3)
  );c:Collab/PopUp#OnInitialize

  ;; retreive values for later use or control other usercontrols
  (defun c:Collab/PopUp/Checkbox1#OnClicked(newValue) (setq nValue1 newValue))
  (defun c:Collab/PopUp/Checkbox2#OnClicked(newValue) (setq nValue2 newValue))
  (defun c:Collab/PopUp/Checkbox3#OnClicked(newValue) (setq nValue3 newValue))

  (dcl_Form_Show Collab_PopUp) ;;;call the method to show the Collab dialog box example


  ;; make something with the values
  (if (/= nValue1 (getvar "USERI1")) (setvar "USERI1" nValue1))
  (if (/= nValue2 (getvar "USERI2")) (setvar "USERI2" nValue2))
  (if (/= nValue3 (getvar "USERI3")) (setvar "USERI3" nValue3))
  (princ)
); collab

With regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

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

CADworker

  • Member
  • *
  • Posts: 6
Re: Help tying lisp to buttons and check boxes
« Reply #2 on: July 30, 2021, 05:33:05 AM »
Thanks for the help there. I see what your doing, checking if box has been checked and adding to a variable. I'm still lost though. I've been combing through the samples and still struggling to figure out how to make the buttons work.

CADworker

  • Member
  • *
  • Posts: 6
Re: Help tying lisp to buttons and check boxes
« Reply #3 on: July 30, 2021, 06:02:32 AM »
So i think my biggest struggle is finding out how to make the buttons runs lisp. I can't seem to find any of the samples that do so.

Fred Tomke

  • OpenDCL Technician
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2070
  • [ Mr. Bad Guy ]
    • Kommunale Entwicklungsplanung auf digitaler Basis - digital landscape and urban design
Re: Help tying lisp to buttons and check boxes
« Reply #4 on: July 30, 2021, 06:21:13 AM »
Hi, you have to make sure, that you activated the events like you did with c:Collab/PopUp#OnInitialize. Then save the project, reload the project and define the event functions.
With regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

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

CADworker

  • Member
  • *
  • Posts: 6
Re: Help tying lisp to buttons and check boxes
« Reply #5 on: July 30, 2021, 06:37:41 AM »
I have added the event trigger for this button. The default is a message prompt when clicked. How do I write the code to run a lisp when clicked.

CADworker

  • Member
  • *
  • Posts: 6
Re: Help tying lisp to buttons and check boxes
« Reply #6 on: July 30, 2021, 07:15:06 AM »
Here is a go with what I have found others doing but its not working, I'm getting a "nil" return. I'm trying to at least get the "Save" button to work.
Any help?

Code: [Select]

____________________________________________________________________________________________________________________________
(defun c:Collab (/ c:Collab/PopUp#OnInitialize
   c:Collab/PopUp/Checkbox1#OnClicked
   c:Collab/PopUp/Checkbox1#OnClicked
   c:Collab/PopUp/Checkbox1#OnClicked
   nValue1 nValue2 nValue3)
 
  (if (not dcl_Project_Load) (command "OPENDCL")) ;;;Ensure the appropriate OpenDCL ARX file is loaded
  (dcl_Project_Load "Collab" T) ;;;call the method to load the Collab.odcl file.
 

  ;;;--------------------------------------
  (defun c:Collab/PopUp/CloseButton#OnClicked () (dcl-form-close Collab/PopUp));;;after dcl-form-close "name of dcl file/name of form"

(defun c:Collaboration3/Form1/SaveButton#OnClicked (/)
  (dcl-Invoke "c:saveorg")
  (dcl-SendString "(c:saveorg)")
)


  (defun c:Collaboration3/Form1/CollabButton#OnClicked (/)
  (dcl-MessageBox "To Do: code must be added to event handler\r\nc:Collaboration3/Form1/CollabButton#OnClicked" "To do")
)
  ;;;--------------------------------------

 

  ;;;Sample code to get values
  (setq nValue1 (getvar "USERI1"))
  (setq nValue2 (getvar "USERI2"))
  (setq nValue3 (getvar "USERI3"))

  ;;;set values of labels
  (defun c:Collab/PopUp#OnInitialize (/)
    (dcl-Control-SetCaption Collab/PopUp/Label1 "Do you wish to SAVE before changes?")
    (dcl-Control-SetCaption Collab/PopUp/Label2 "Set UCS to world")
    (dcl-Control-SetCaption Collab/PopUp/Label3 "Detach XRef's")
    (dcl-Control-SetCaption Collab/PopUp/Label4 "One Viewport at PlanView")

   ;;;set values
    (dcl-Control-SetValue Collab/PopUp/Checkbox1 nValue1)
    (dcl-Control-SetValue Collab/PopUp/Checkbox2 nValue2)
    (dcl-Control-SetValue Collab/PopUp/Checkbox3 nValue3)
  );;;c:Collab/PopUp#OnInitialize

  ;;;retreive values for later use or control other usercontrols
  (defun c:Collab/PopUp/Checkbox1#OnClicked(newValue) (setq nValue1 newValue))
  (defun c:Collab/PopUp/Checkbox2#OnClicked(newValue) (setq nValue2 newValue))
  (defun c:Collab/PopUp/Checkbox3#OnClicked(newValue) (setq nValue3 newValue))

  (dcl_Form_Show Collab_PopUp) ;;;call the method to show the Collab dialog box example


  ;;;make something with the values
  (if (/= nValue1 (getvar "USERI1")) (setvar "USERI1" nValue1))
  (if (/= nValue2 (getvar "USERI2")) (setvar "USERI2" nValue2))
  (if (/= nValue3 (getvar "USERI3")) (setvar "USERI3" nValue3))

 
); collab


(defun saveorg ()
  (command "qsave")
  )

Fred Tomke

  • OpenDCL Technician
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2070
  • [ Mr. Bad Guy ]
    • Kommunale Entwicklungsplanung auf digitaler Basis - digital landscape and urban design
Re: Help tying lisp to buttons and check boxes
« Reply #7 on: July 30, 2021, 11:57:50 PM »
Hi, why of all things did you start working with OpenDCL using _qsave command (I recommend you to use international type writing of AutoCAD-commands)?
Honestly. Please remind two things: First of all, do not call a command from a running modal form. You can do this after closing the form and give back control to AutoCAD - OR - from a modeless form (like palette) (which is not running in KeepFocus-mode) from a control whose EventInvoke-property is set to "AllowCommand". Second, you cannot get access to the database (open, close, modify drawing entities) from a running modal form. The solutions are the same like mentioned before.

Please have a look at this FAQ.
With regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

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

CADworker

  • Member
  • *
  • Posts: 6
Re: Help tying lisp to buttons and check boxes
« Reply #8 on: August 04, 2021, 06:18:27 AM »
I was just testing commands trying to get something to work. "Qsave" happened to be in my lisp when I copied my code to post.

Again, like I've said before, I'm NEW to opendcl. I'm trying to get some help but I'm being re-directed to the samples every time. The problem there is none of those samples, from what I understand, show how to run lisp after buttons have been clicked. My previous employer had created a dialog to do something like this very similar without using opendcl. I thought this program would be easier to create what I'm needing but so far the help has been, quite frankly, a bit rude.

I do like seeing the modal as you make it. That is helpful. I'm just struggling on how to make it work with lisp.


Fred Tomke

  • OpenDCL Technician
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2070
  • [ Mr. Bad Guy ]
    • Kommunale Entwicklungsplanung auf digitaler Basis - digital landscape and urban design
Re: Help tying lisp to buttons and check boxes
« Reply #9 on: August 09, 2021, 06:33:42 AM »
Hi, CADWorker,

sorry when my answer seemed to be rude. It was not my aim to do so. It took some time to find the words how to make sure calling commands from a modal form accessing the database is one of the few little things which can be quite challenging in OpenDCL. In fact, until AutoCAD 2015 some database modifications where possible. But then Autodesk removed fiber technology which has broken many Lisp-programs using OpenDCL. Not necessary to mention that I have nearly the same challenges in C#/.NET.

Of course, I've had seen that you've just started with OpenDCL, so my excited answer was not well-formed what leads my to my apologize.
Again, if you have a modal form, you have to deal it that way (note: its dummy code):

Code: [Select]
(defun c:main(/ c:MyProj/MyForm#OnInitialize c:MyProj/MyForm/pbAccept#OnClick retValue
                         c:MyProj/MyForm/pbCancel#OnClick c:MyProj/MyForm/pbGetPoint#OnClick)

    (defun c:MyProj/MyForm#OnInitialize()
      ;; set the controls
    ); c:MyProj/MyForm#OnInitialize()

    (defun c:MyProj/MyForm/pbAccept#OnClick()
      (dcl-form-close MyProj/MyForm 1)
      ;; form is still active, no complete access to the drawing
    ); c:MyProj/MyForm/pbAccept#OnClick

    (defun c:MyProj/MyForm/pbCancel#OnClick() (dcl-form-close MyProj/MyForm 2))

    (defun c:MyProj/MyForm/pbGetPoint#OnClick()
      (dcl-form-close MyProj/MyForm 3)
      ;; form is still active, no complete access to the drawing
    ); c:MyProj/MyForm/pbGetPoint#OnClick

    (while (not (member (setq retValue (dcl-form-show MyProj/MyForm)) '(1 2)))
      ;; form is not active anymore, the control was given back to AutoCAD
      (cond
        ((= retValue 3) (setq ptPoint (getpoint "\r\nPick point: ")))
      ); cond
    ); while
    (if (= retValue 1)
      (progn
        (store_data_to_drawing)
        (command "_qsave")
      ); progn
    ); if

); c:main

So I hope the sample code gives you an idea how to deal with re-showing a form or finally modify the drawing database.
Maybe it would be more helpful to have  the project you try to build for much better answers.

With regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

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