AutoCAD/DCL problem

Advertisement


Question

Hello Mr.Scott,

I use AutoCAD 2004 and have a problem in dcl programming, especally in the lisp coding behind the dcl (I'm a beginner in dcl).

Just for a drill, I create a dialog box with 3(three) or more radio buttons, say each button assigned line, circle and rectangular command when you click the OK button.

The problem is when you select one radio button and you cancel your selection by selecting another radio button (and again another radio button), then it won't work as what it is expected to.

Here are the files :

DCL file :

DRAW_BOX : dialog { label = "DRAW DIALOG BOX" ;
                     :boxed_column { label = "Select Objects :" ;
                                    :radio_column {
                                                   :radio_button {key = "line"  ;label = "Line"       ;mnemonic = "L";}
                                                   :radio_button {key = "circle";label = "Circle"     ;mnemonic = "C";}
                                                   :radio_button {key = "rec"   ;label = "Rectangular";mnemonic = "R";}
                                                   :radio_button {key = "poly"  ;label = "Polygon"    ;mnemonic = "P";}
                                                  }
                                   }
                      ok_cancel;
                    }

LSP file :

(defun c:draw_b(/ dcl_id l2 c2 r2 p2)
 (setq dcl_id (load_dialog "draw.dcl"))
 (new_dialog "DRAW_BOX" dcl_id)
 
 (setq l1 (get_tile "line"  ))
 (setq c1 (get_tile "circle"))
 (setq r1 (get_tile "rec"   ))
 (setq p1 (get_tile "poly"  ))

 (action_tile "line"   "(setq l2 $value)")
 (action_tile "circle" "(setq c2 $value)")
 (action_tile "rec"    "(setq r2 $value)")
 (action_tile "poly"   "(setq p2 $value)")
 
 (action_tile "accept" "(done_dialog) (setq     click T)")
 (action_tile "cancel" "(done_dialog) (setq click nil)")  
 
 (start_dialog)  
 (done_dialog)  
 
 (if (and (= l2 "1") click) (command "line"   ))
 (if (and (= c2 "1") click) (command "circle" ))
 (if (and (= r2 "1") click) (command "rectang"))
 (if (and (= p2 "1") click) (command "polygon"))
 
 (princ)
)

(princ)

I would be very thankful if you kindly answer my email together with the solution for my problem.


Regards,

Ruslin

Answer
There's probably half-a-dozen ways to solve this problem, all dealing with coding style and ways to handle events.
The root of your problem is this:
Since you are using four variables, you need to clear the other three variables when you select one of the radio buttons. DCL doesn't call the action tiles for the other three - only the one that was clicked. You have no "unclick" event for any of the radio buttons.

so if you setq l2 to something when it is clicked, you need to setq the others to nil.
(setq l2 T
     c2 nil
     r2 nil
     p2 nil
)

OR, a more elegant way is that if you use one variable to represent the clicked radio button, you won't have to worry about clearing the others.
(setq whichone $key)

You don't have to assign the action_tiles individually to each thing you want to know about - I tend to use a "global" dialog handler for everything these days:
(setq newd (new_dialog "dialogname" dia "(my-handler $key $value $reason)" ))
You then define a function body to handle all the keys in a big COND statement:
(defun my-handler (key value reason)
 (cond
   ((= key "line")
     ;... do something
   )
   ((= key "circle"
     ;... etc
   )
   ;.. and so on
 )
)
In your case, you dialog handler only needs to do one thing. set one variable to represent which radio button was selected.

AutoCAD

All Answers


Answers by Expert:


Ask Experts

Volunteer


Scott Cook

Expertise

I`ve been using AutoCAD since 1987 and programming AutoLISP nearly as long. I can answer questions about programming AutoCAD (except ARX) and production enhancement techniques. I cannot answer questions about AutoCAD crashes or DWG corruption. AutoCAD PROGRAMMING (menus, lisp) related questions only!

Experience

Since 1987. Author of Plot2000 software for for AutoCAD, http://www.plot2000.com. PROGRAMMING QUESTIONS ONLY PLEASE. Questions that are NOT related to programming or AutoCAD customization (menus and lisp only please) are outside the scope of my volunteer services and will NOT BE ANSWERED.

©2012 About.com, a part of The New York Times Company. All rights reserved.