Trying to understand dcl buttonclick

Trying to understand dcl buttonclick

My_Civil_3D
Advocate Advocate
1,344 Views
12 Replies
Message 1 of 13

Trying to understand dcl buttonclick

My_Civil_3D
Advocate
Advocate

Hi Guys

i am trying to understand the buttonclick in a dcl file.

 

i have a button with key = "Button1" .

Lets say for example i want to run the autocad circle command when the button is pressed! THis is what i came up with i dont think its correct so please help me:

 

(action_tile "Button1" "(circle)")

 

 

 

Civil 3D Certified Professional
0 Likes
1,345 Views
12 Replies
Replies (12)
Message 2 of 13

paullimapa
Mentor
Mentor

Typically to return to the graphics screen to draw you’ll have to dismiss the dialog with done_dialog followed by a number code so the original start_dialog function call will return this and then you can setup cond statements to run commands like drawing circles and etc

checkout afralisp website for a number of dcl examples

https://www.afralisp.net/dialog-control-language/ 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 13

paullimapa
Mentor
Mentor

Samplebuttons.lsp is an example that automatically generates a dcl based on your OP but with 3 additional draw buttons added to meet this example.

Basically the lisp writes the dcl on the fly into the temp folder.

A loop is setup so the dialog will continue to display until you press the OK button

In addition to the OK button I've setup 3 action_tile call back sample functions for Draw Circle, Square & Rectangle

When any one of those buttons are pressed the dialog is dismissed for the object to be drawn using the condition statements. After completing the drawing commands the dialog will be displayed again for additional selections.

Finally, when the dialog is permanently dismissed with the OK button the dcl file is deleted for a clean exit.

Let me know if you have any questions.

paullimapa_0-1682799395985.png

 

 

; SAMPLEBUTTONS function demonstrates using buttons & dialog display loop
(defun C:SAMPLEBUTTONS (/ button-name dcl dcl-id do_wrt_dcl what-next) ; local variables
;;;---load vl functions
(if(not(car (atoms-family 1 '("vl-load-com"))))(vl-load-com))

;;;---do_wrt_dcl function writes DCL file on the fly
(defun do_wrt_dcl (name / fp)
  (if (and name (setq fp (open name "w")))
    (mapcar 
      '(lambda (x)(write-line x fp))
       (list
               "picture_dcl1 : dialog {" 
               "label = \"DRA STANDARDS\";" 
               ": row {" 
               "    children_alignment = top;" 
               "    children_fixed_height = true;" 
               "    : boxed_column {" 
               "        label = \"ARROWS\";" 
               "        mnemonic = \"A\";" 
               "        : button {" 
               "            label = \"NORTH ARROW\";" 
               "            key = \"BtnNorth\";" 
               "            mnemonic = \"N\";" 
               "        }" 
               "        : button {" 
               "            label = \"FALL / SLOPE\";" 
               "            key = \"BtnFallSlope\";" 
               "            mnemonic = \"F\";" 
               "        }" 
               "        : button {" 
               "            label = \"FLOW DIRECTION\";" 
               "            key = \"BtnFlowDirection\";" 
               "            mnemonic = \"W\";" 
               "        }" 
               "        : button {" 
               "            label = \"DIRECTION ARROW\";" 
               "            key = \"BtnDirection\";" 
               "            mnemonic = \"D\";" 
               "        }" 
               "        : button {" 
               "            label = \"LEVEL ARROW\";" 
               "            key = \"BtnLevelArrow\";" 
               "            mnemonic = \"L\";" 
               "        }" 
               "    }" 
               "    : boxed_column {" 
               "        label = \"HEADERS\";" 
               "        mnemonic = \"H\";" 
               "        children_fixed_height = true;" 
               "        : button {" 
               "            label = \"LAYOUT HEADER\";" 
               "            key = \"LayoutHeader\";" 
               "            mnemonic = \"A\";" 
               "        }" 
               "        : button {" 
               "            label = \"SECTION / DETAIL HEADER\";" 
               "            key = \"SectionHeader\";" 
               "            mnemonic = \"E\";" 
               "        }" 
               "        : button {" 
               "            label = \"DRAW CIRCLE\";" 
               "            key = \"BtnCircle\";" 
               "            mnemonic = \"C\";" 
               "        }" 
               "        : button {" 
               "            label = \"DRAW SQUARE\";" 
               "            key = \"BtnSquare\";" 
               "            mnemonic = \"S\";" 
               "        }" 
               "        : button {" 
               "            label = \"DRAW RECTANGLE\";" 
               "            key = \"BtnRectangle\";" 
               "            mnemonic = \"R\";" 
               "        }" 
               "    }" 
               "}" 
               "ok_only;" 
               "}" 
      )
    )
  )
  (if fp (close fp))
 ) ; defun do_wrt_dcl

 ;;;---Write dcl on the fly to temp folder
 (do_wrt_dcl (setq dcl (vl-filename-mktemp "SAMPLEBUTTONS.dcl")))

 ;;;---Load the dcl file from disk into memory
 (if (not (setq dcl-id (load_dialog dcl))) 
  (progn
   (alert "SAMPLEBUTTONS.dcl file could not be loaded!")
   (exit)
  )

  ;;;---Else, the DCL file was loaded
  (progn
    ;;;---Start the dialog display loop
   (setq what-next 2)
   (while (> what-next 1)

   ;;;---Load the dialog name inside the DCL file
    (if (not (new_dialog "picture_dcl1" dcl-id))
     (progn
      (alert "The picture_dcl1 dialog from SAMPLEBUTTONS.dcl file could not be loaded!")
      (exit)
     )
    ;;;---Else, the dialog name was found
     (progn
    ;;;---Setup action_tile call back statements
      (action_tile "BtnCircle" "(setq button-name $key)(done_dialog 4)") ; Draw Circle Button
      (action_tile "BtnSquare" "(setq button-name $key)(done_dialog 3)") ; Draw Square Button
      (action_tile "BtnRectangle" "(setq button-name $key)(done_dialog 2)") ; Draw Rectangle Button
      (action_tile "accept" "(setq button-name $key)(done_dialog 1)") ; end display dialog while loop

      ;;;---Display the dialog box
      (setq what-next (start_dialog)) 

      ;;;---Inform user the results
      (princ (strcat"\npicture_dcl1 Button Labelled [" button-name "] with Callback Number [" (itoa what-next) "] was Selected!\n"))

      ;;;---Begin condition statements to check call back code
      (cond
       ;;;---If the user pressed the Draw Square button
       ((= what-next 4)
        (vl-cmdf "_.Circle")
        (while (= 1 (logand 1 (getvar 'CMDACTIVE))) (command pause)) ; while there's an active command pause
       )
       ;;;---If the user pressed the Draw Square button
       ((= what-next 3)
        (vl-cmdf "_.Polygon""4""_E")
        (while (= 1 (logand 1 (getvar 'CMDACTIVE))) (command pause)) ; while there's an active command pause
       )
       ;;;---If the user pressed the Draw Rectangle button
       ((= what-next 2)
        (vl-cmdf "_.Rectangle")
        (while (= 1 (logand 1 (getvar 'CMDACTIVE))) (command pause)) ; while there's an active command pause
       )
       ;;;---If the user pressed the OK button
       ((= what-next 1)
        (princ "\npicture_dcl1 completed!")
       )
      ); cond
     ) ; progn
    ) ; if load dialog name
   ) ; while loop

   ;;;---Unload the dialog box
   (unload_dialog dcl-id)

   ;;;---Delete the dialog box file
   (vl-file-delete dcl)
  ) ; progn
 ) ; if load dcl file
 ;;;---Suppress the last echo for a clean exit
 (princ) ; clean exit
); C:SAMPLEBUTTONS

 

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 4 of 13

Sea-Haven
Mentor
Mentor

This uses radio buttons as an example it returns the radio button label string "Ans" or the button number pressed "But", it closes the dialog when a button is pressed or OK is selected. Not the (done_dialog) in the code.

0 Likes
Message 5 of 13

My_Civil_3D
Advocate
Advocate

been sitting with this for a while now and still cant figure it out, with all respect to everyone helping i dont think by giving me a bunch of code and sending me on my way helps. i have no real experience with lisp and dcl but trying as i go along and i dont even know what half f the stuff do what you guys sent me

Civil 3D Certified Professional
0 Likes
Message 6 of 13

paullimapa
Mentor
Mentor

Well first you need to learn how to code in AutoLISP / visual lisp before jumping into doc programming. Go with the link I sent you in my first reply to learn both. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 13

Sea-Haven
Mentor
Mentor

Writing dcl takes a bit of time to learn and I still stuff it up now and then. 

 

Ok a suggestion note the (done _dialog)

 

(action_tile "BtnCircle" "(setq button-name $key)(done_dialog)") ; Draw Circle Button

 

You need to have a action_tile for every key, the way I got around this in the multi radio buttons is to use a loop and just use "Keyx" as the key label eg Key1, Key2... Like wise once you click OK another loop looks at which key was pressed, So returns say "Key4" then use a Cond for the action like circle.

 

Ok found another problem you use (setq button-name $key) but in your cond your using (= what-next 1) rather than (= button-name "BtnCircle" )

 

I also reset the (done_dialog) with no number in the action_tile line. 

 

Next was I got stuck in a loop of the dcl being called. I would remove the following .

 

    ;;;---Start the dialog display loop
   (setq what-next 2)
   (while (> what-next 1)

 

 

See attachment a full edited version. I am sure others will other suggestions also.

0 Likes
Message 8 of 13

sachindkini
Advocate
Advocate
(defun C:test( / id i ok)
  (setq id (load_dialog "test.DCL"))	;load DCL
  (if (new_dialog "dcl_test" id)
    (progn
      (setq i 1)
      (repeat 6
        (init_image i)				;assign an action to the image_button
	;(action_image i)			
	(setq i (1+ I))	
      )
      (action_tile "C1" "(action_command 1)") 	;assign an action to the button 1
      (action_tile "C2" "(action_command 2)") 	;assign an action to the button 2
      (action_tile "C3" "(action_command 3)") 	;assign an action to the button 3
      (action_tile "C4" "(action_command 4)") 	;assign an action to the button 4
      (action_tile "C5" "(action_command 5)") 	;assign an action to the button 5
      (action_tile "C6" "(action_command 6)") 	;assign an action to the button 6

      ;;of course ,you can do it by (repeat)
      (setq ok (start_dialog))
    )
    (alert "Can't load the dialoag!")
  )
  (unload_dialog ID)
  (princ)
)

;;; initializate the image_button.
;;; and assign an action to an image_button
(defun init_image (key / k tile)
  (setq k (itoa key))
  (setq tile  (strcat "I" k))				;tile
  (start_image tile)
  (fill_image
    0
    0
    (dimx_tile tile)
    (dimy_tile tile)
    key
  )
  (end_image)						;fill tile with different color
  (set_tile tile (strcat "Fun" k))			;set the text of tile
  (action_tile tile (strcat "(action_command " k ")"))	;action
)

;;; assign an action to an command_button
(defun action_command (key)
  (cond
    ((= key 1)
     (alert "Please enter  your command1:")
     ;;add your code in here
    )
    ((= key 2)
     (alert "Please enter  your command2:")
     ;;add your code in here
    )
    ((= key 3)
     (alert "Please enter  your command3:")
     ;;add your code in here
    )
    ((= key 4)
     (alert "Please enter  your command4:")
     ;;add your code in here
    )
    ((= key 5)
     (alert "Please enter  your command5:")
     ;;add your code in here
    )
    ((= key 6)
     (alert "Please enter  your command6:")
     ;;add your code in here
    )
  )
)

 

//test.dcl
dcl_test : dialog
{
  label = "Test dialog";
  : boxed_column
  {
    :row	//the first row  for command buttons.
    {
      : button
      {
        key = "C1";
        label = "command1";
      }
      : button
      {
        key = "C2";
        label = "command2";
      }
      : button
      {
        key = "C3";
        label = "command3";
      }
    }
    :row	//the second row for command buttons.
    {
      : button
      {
        key = "C4";
        label = "command4";
      }
      : button
      {
        key = "C5";
        label = "command5";
      }
      : button
      {
        key = "C6";
        label = "command6";
      }
    }
    :row      	//the third row  for image buttons 
    {
      : image_button  
      {
        key = "I1";
        width = 6;
        height = 3;
        aspect_ratio = 1;
        fixed_width = true;
        fixed_height = true;
        alignment = centered;
        color = -2;
      }
      : image_button
      {
        key = "I2";
        width = 6;
        height = 3;
        aspect_ratio = 1;
        fixed_width = true;
        fixed_height = true;
        alignment = centered;
        color = -2;
      }

      : image_button
      {
        key = "I3";
        width = 6;
        height = 3;
        aspect_ratio = 1;
        fixed_width = true;
        fixed_height = true;
        alignment = centered;
        color = -2;
      }
      : image_button
      {
        key = "I4";
        width = 6;
        height = 3;
        aspect_ratio = 1;
        fixed_width = true;
        fixed_height = true;
        alignment = centered;
        color = -2;
      }
      : image_button
      {
        key = "I5";
        width = 6;
        height = 3;
        aspect_ratio = 1;
        fixed_width = true;
        fixed_height = true;
        alignment = centered;
        color = -2;
      }

      : image_button
      {
        key = "I6";
        width = 6;
        height = 3;
        aspect_ratio = 1;
        fixed_width = true;
        fixed_height = true;
        alignment = centered;
        color = -2;
      }
    }
  }
  spacer_1;
  ok_cancel_help;
  //errtile;
}  
0 Likes
Message 9 of 13

Sea-Haven
Mentor
Mentor

This is a library function for 2 column radio buttons only need a few of lines of code to run.

 

 

(if (not ah:buttscol)(load "Multi Radio buttons 2col.lsp"))
(if (= ah:2col nil)(setq ah:2col 1))
(if (= ah:2col2 nil)(setq ah:2col2 1))
(setq lst1 (list "Select number" "1" "2" "3" "4" "5" "6" "7" "8" "9" "10"))
(setq lst2 (list "Select Char" "A" "B" "C" "D"))
(ah:buttscol ah:2col ah:2col2 "Please choose" lst1 lst2)
(setq ans1 (nth ah:2col lst1))
(setq ans2 (nth ah:2col2 lst2))

 

0 Likes
Message 10 of 13

My_Civil_3D
Advocate
Advocate

Here is a simple test i have done and i am getting this error: ive been reading and reading but cant seem to grasp this

 

dominiqueS4ANP_0-1683479093013.png

 

Here is my Lisp and my dcl code:

 

DCL:

circle_dcl

:dialog
{
label = "TEST";

:row
{
:button{key = "circle";label = "TEST"; value = "0";}
}
ok_only;
}

 

Lisp:

(defun c_circle ()

(setq pt (getpoint "\nSelect Centre Point:"))
(setq rad (getreal "\nEnter Raduis:"))
(command "Circle" pt rad)
)


(defun c:test ()
  (setq dcl_id (load_dialog "circle_dcl.dcl"))

  (if (not (new_dialog "circle_dcl" dcl_id))
    (exit)
  )


(action_tile "circle" "(c_circle)(done_dialog 1)")

(action_tile "ok" "(done_dialog)")

 (setq dialog (start_dialog))
 (unload_dialog dcl_id)

  )

 

Civil 3D Certified Professional
0 Likes
Message 11 of 13

paullimapa
Mentor
Mentor

You have a good start. In this case since your action call back statement is to draw sa circle on the graphics screen you have to dismiss the dialog first before calling your draw circle function

(action_tile "circle" "(done_dialog 1)")

Then you can do an if statement test for the dialog variable like this

(if (= 1 dialog)(c_circle))

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 12 of 13

My_Civil_3D
Advocate
Advocate

have tried this autocad returns nil

Civil 3D Certified Professional
0 Likes
Message 13 of 13

paullimapa
Mentor
Mentor

Post your revised code


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes