AutoCAD/Mode_tile for popup
Expert: Scott Cook - 9/30/2009
QuestionQUESTION: Hi Scott,
I'm Don and i have a question if i may ask you.
I have a question about Mode_tile for a toggle button.
i have a popup where i can select a paperformat.
You can choose between 10 size's from A0 till A4
The list return 0 till 9 corresponding A0 till A4.
0 = A0 and 9 = A4
Wel if i use this action_tile
(action_tile "paperformat" "(setq toggle1 $value)(mode_tile "but7" (- 7 (atoi toggle1)))")
toggle1 is used to set default data
saving and restoring default data is working fine.
the popup wil only hide but7 if i select entry nr 7 from the list and unhide but 7 if i select entry nr 6.
The thing i want is that but7 is hide when entry nr 6, 7, 8 and 9 is selected and when 0, 1, 2, 3, 4 and 5 is slected but7 has to unhide itself
Is it possible to make a action_tile that do this?
If you need more info just let me know.
Greetings
Don
ANSWER: I think you are going to have to use a conditional with greater and less than ranges instead of the math you are doing now and set mode_tile to 0 or 1 accordingly.
I also find it easier to use one function call to handle events for the entire dialog instead of the individual action_tile method you are doing now. There is an example of this in the manual. You won't have to worry about the embedding of strings in your handler that way.
---------- FOLLOW-UP ----------
QUESTION: Hi scott,
Thanks for your answer.
I read the manual you told about,
bud i can't find anything you told about in this manual.
Please can you send me the url of the page where i can find an example.
Greetings
Don
AnswerThe new_dialog function call can specify the default action handler. I was unable to find any good examples of how to do a global handler on the internet or manual, so this is why it's taken me time to get back to you. I had to go dig in my code to see how I had done it in the past.
Basically, the deal is you should define your own function that gets called as the default handler, then check for the key and value variables in a big conditional to deal with each dialog event.
The benefit of this method is that you aren't trying to cram a bunch of stuff into action_tile statements that have quoted strings, etc.
(setq dia (load_dialog (findfile "mydialog.dcl")))
;define the global handler in the new_dialog call below
(setq newd (new_dialog "my_dialog_box" dia "(my_handler $key $value)"))
;initialize your default values and stuff here
;do your start_dialog, done_dialog return value checking, and unload_dialog stuff as normal
;now define the function that gets called for every dialog action and trap the stuff you are interested in
(defun my_handler (key value)
;$key The key attribute of the tile that was selected.This variable applies to all actions.
;$value The string form of the current value of the tile, such as the string from an edit box, or a "1" or "0" from a toggle.This variable applies to all actions.If the tile is a list box (or pop-up list) and no item is selected, the $value variable will be nil.
;uncomment the line below to see what is going on
;(princ (strcat "\nKey: " key " Value: " value))
(cond
((= key "MY_TILE1")
; do some work
)
((= key "WHATEVER_TILE")
;do some other work
)
;you need default accept/cancel handlers
((= key "accept")
(done_dialog 1) ;these values get returned to your start_dialog call
)
((= key "cancel")
(done_dialog 0) ;gets returned to your start_dialog call
)
)
)