• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Visual LISP, AutoLISP and General Customization

    Reply
    Distinguished Mentor
    Moshe-A
    Posts: 679
    Registered: ‎09-14-2003
    Accepted Solution

    problem in callback function

    142 Views, 5 Replies
    09-15-2012 03:17 PM

    Hi Guys,

     

    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

    Moshe

     

     

    Please use plain text.
    *Pro
    scot-65
    Posts: 1,928
    Registered: ‎12-11-2003

    Re: problem in callback function

    09-17-2012 03:24 PM in reply to: Moshe-A

    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)"
    Please use plain text.
    *Expert Elite*
    Posts: 2,063
    Registered: ‎11-24-2009

    Re: problem in callback function

    09-17-2012 06:06 PM in reply to: scot-65

    scot-65 wrote:

    ....

    I personally keep the done_dialog on the same line as "accept". It's easier for me to follow...

    .....


     

    I concur...

     

    Please use plain text.
    Distinguished Mentor
    Moshe-A
    Posts: 679
    Registered: ‎09-14-2003

    Re: problem in callback function

    09-18-2012 12:38 AM in reply to: scot-65

    Hi Scot,

     

    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.

     

    Moshe

     

    Please use plain text.
    Distinguished Mentor
    Moshe-A
    Posts: 679
    Registered: ‎09-14-2003

    Re: problem in callback function

    09-18-2012 02:11 AM in reply to: scot-65

    Scot,

     

    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?

     

    thanks

    Moshe

     

      

    Please use plain text.
    *Pro
    scot-65
    Posts: 1,928
    Registered: ‎12-11-2003

    Re: problem in callback function

    09-18-2012 04:04 PM in reply to: Moshe-A

    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.

     ...

     (princ)

    );end MAIN

     

    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(?).

     

    ???

     

    Please use plain text.