i have encounter a problem in callback function...i am using (client_data_file) to attach string (in a list)
to be transfer to callback function. in the callback i set a local variable to get this string and autocad set it
to nil but if i declare the variable as global it works (not sure if it is a steady problem)
does any one seen this or am i missing something?
here is an example of my code:
(setq some_string "abcde") (client_data_tile "accept" "(some_string)") (action_tile "accept" "(ctrl_accept $data)") (defun ctrl_accept (data / str) (setq str (eval (car (read data)))) ; this returns nil (done_dialog 1) ) ; but this one works (defun ctrl_accept (data) (setq str (eval (car (read data)))) ; this returns "abcde" (done_dialog 1) )
thanks in advance
Solved! Go to Solution.
For your first defun you declare a local variable STR which does not leave the
confides of the opening and closing parenthesis of the defun. In other words,
it is a local variable that stays local. If you want it to leave this area, you show
one of the many tricks that are available.
I personally keep the done_dialog on the same line as "accept". It's easier for me to follow...
Try this (untested)
(defun ctrl_accept (data) (eval (car (read data))) )
..."(setq str (control_accept $data))(done_dialog 1)"
thank you very much for your help.
i expand a little of what i'm doing:
suppose in main function i have a registry key and a file name
(that were build in main and ofcourse defined as locals) as the user picks th OK button
i need them in the (ctrl_accept) callback function to write the file name to registry.
all of that include some error cheaking could not be done from (action_tile) call
i suppose you agree with me?!
the problem arise in buttons i use and edit_box tiles.
this code is a small example of my program
(defun ctrl_accept (data / rkey filename) (setq rkey (eval (car (read data))) (setq filename (eval (cadr (read data)))) (if (vl-registry-read rkey) (vl-registry-write rkey "datafilename" filename) ) (done_dialog 1) ) (defun c:main (/ rkey filename dcl_id what_next) (setq rkey (strcat "HKEY_LOCAL_MACHINE\\" (vlax-product-key) "\\Applications") rkey (strcat rkey "\\AppName") ) (if (not (vl-registry-read rkey)) (vl-registry-write rkey) ) (setq filename "appdata.txt") (setq dcl_id (ai_dcl "appdata")); load dcl file (setq what_next 3) (While (> what_next 1) (if (not (new_dialog "app_dialog" dcl_id "" '(-1 -1))); open dialog (exit) ) (client_data_tile "accept" "(rkey filename)") (action_tile "accept" "(ctrl_accept $data)") (SetQ what_next (start_dialog)); start dialog ); while (princ) )
as i said earlier the problem is not steady it arise from time to time
but i can not relay on it.
i have changed the local variable name and it seems that autocad is pleased with that
(wonder why in callback a local variable 'filename' is not accepted but 'fname' does -
undocumented bug?) hope it will stay
Scot, could you take a look at my other theard TDINDWG v TDUSRTIMER?
I'm not sure what is "client_data_tile"?
It's not set_tile, mode_tile, or action_tile.
Getting past that, what is "(rkey filename)"? Looks like a call to a subroutine?
If you want the gremlin to remain inside a program, yet still have access to that
gremlin while inside a function (subroutine) restructure your program as follows:
(defun c:MAIN ( / a b c...)
(defun SUB1 (f g / h k...) ... ) ;a b c f and g can be seen inside here, h and k is local to SUB1.
(defun SUB2 (m / n...) ... ) ;again, a b c and m can be seen inside here, n is local to SUB2.
One might have conflicts with declared variables (gremlins) for this structure above.
I have used a suffix "1", "2", etc. inside my subs, especially with numbers or counters
(sslength, setq n1, etc.).
TDINDWG Time Display in Drawing I looked at once upon a time,
but never investigated the other one (is it a Dunsel variable???).
We use UNNAMED profiles here. It serves us no purpose(?).
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register
Start with some of our most frequented solutions to get help installing your software.