Nice tool for localizing variables

Discussion in 'AutoCAD' started by James Maeding, Aug 13, 2004.

  1. I just thought this might be useful...
    I hate the task of going through lisps and making a list of the variables, then adding them after the / in the defun.

    So I got a seat of LispLink from http://www.caelink.com/lisplink.htm
    No I do not work for them.

    They have a super feature where you highlight the function name and pick a button.
    It brings up a dialog with a list of the vars, you choose which ones to add to the loaclized list (i.e. after the / in
    the defun)
    It adds them and the task is done. Super slick.

    So the fast way to use this is to open LispLink and open a blank file and save it.
    Then when you bring up the prog, it brings up that blank lisp.
    You paste in your code and run the localizer. Then copy the code back to the vlisp editor or wherever.

    Its worth the $30 or whatever the price is.
    Curiuos to see if others have slicker tools for this.
    James Maeding
    Civil Engineer/Programmer
     
    James Maeding, Aug 13, 2004
    #1
  2. James Maeding

    Tom Smith Guest

    I hate the task of going through lisps and making a list of the variables

    I suppose everyone has their own methods. Some old books used to actually
    advise leaving variables undeclared, supposedly for debugging purposes,
    until the program was finished. A poor practice, IMHO, because it's not
    uncommon in a function to test whether a variable has yet been been given a
    (local) value. Many of my lisps would never work properly in testing if all
    variables were dangling globals.

    I've always made it a habit to add each variable to the declared locals as
    soon as I type its name in the code the first time. Then there isn't any
    tiresome task to do at the end. Each time I type an opening parenthesis, I
    type a closing parenthesis on the next line, and never need to count or
    match them. Don't let a mess accumulate in the first place, in other words,
    and there's no cleaning up to do later.

    But nevertheless, I see way too many lisps floating around with NO variables
    declared local, and hopefully the people writing them will take advantage of
    your advise.
     
    Tom Smith, Aug 13, 2004
    #2
  3. James Maeding

    BillZ Guest

    <putting on my flame suit>

    I set a variable in my s::startup
    (setq ltq (atoms-family 1)) ;list for chk_values.lsp variable checker.

    Then I have a lisp that I can start on a button after I run a program that I'm working on.

    Here it is:

    ;10/13/99 Bill Zondlo
    ;use this program to clean up your custom autolisp programs.
    ;quickly finds user global variables/functions defined during use of custom programs,
    ;so you can add them to your local variables list without searching each line of program.
    ;------------------------------;
    ;;(setq ltq (atoms-family 1)) ;;add this line to your s::startup to make list at start of drawing session.
    ;------------------------------;
    (defun ck_val (/ ltr ltt) ;after custom program is run, run this program.
    (setq ltt (atoms-family 1)) ;to get list of newly defined variables/functions.
    ;;
    (princ (strcat "\nltq > " (rtos (length ltq) 2 0) " - ltt > " (rtos (length ltt) 2 0))) ;prints length of each list.
    ;;
    (foreach n ltt ;compares each item in new list.
    (if (not (member n ltq)) ;of newly defined variables/functions since start of drawing.
    (setq ltr (append ltr (list n))) ;makes list of new items.
    ) ;end if
    ) ;end foreach
    (if (not (null ltr)) ;if new items.
    (progn
    (textscr) ;flips to text screen.
    (foreach m ltr (princ (strcat "\n " m))) ;prints new items to screen.
    ) ;end progn
    ) ;end if
    (princ)
    ) ;end defun
    (princ)

    It displays a list of new variables set during the drawing session.


    Bill
     
    BillZ, Aug 13, 2004
    #3
  4. James Maeding

    R.K. McSwain Guest


    Not to knock your suggestion, but the visual lisp editor can help also.

    Check Edit Window (or Check Selection) will give you a list of globals.
    See example:

    -------------------------------------------------------------------------
    [CHECKING TEXT INLET.LSP loading...]
    ..
    ; === Top statistic:
    ; Global variables: (ELV FL PR$ PRSCL PT1 PT2 PT3 PT4 PT5 PT6 SCLFAC TR)
    ; Function definition (with number of arguments): ((C:INLET . 0))
    ; Check done.
     
    R.K. McSwain, Aug 13, 2004
    #4
  5. James Maeding

    Tom Smith Guest

    Now that's the kind of tip I like. Free of charge, no programming required,
    already fully integrated, and leaving no excuse for having undeclared locals
    at any point in development. Thanks!
     
    Tom Smith, Aug 13, 2004
    #5
  6. Except that the list can report globals that aren't, or some of the (vl*)
    functions as a global. But I use it all the time to double-check myself (I
    write LISP code similar to you).

    --
    R. Robert Bell


    "Tom Smith" <nospam> wrote in message Now that's the kind of tip I like. Free of charge, no programming required,
    already fully integrated, and leaving no excuse for having undeclared locals
    at any point in development. Thanks!
     
    R. Robert Bell, Aug 13, 2004
    #6
  7. James Maeding

    James Allen Guest

    Thank you SO much! :), I've always suspected that ability was there and
    even searched for it at times to no avail. That is wonderful.

    Thank you.
     
    James Allen, Aug 13, 2004
    #7
  8. I have been using this for about 4 years, I love it. I especially like the
    DCL viewing feature so I can view dialog as I create them.

    Great tool, I highly recommend it.

    Tim


    then adding them after the / in the defun.
    add to the loaclized list (i.e. after the / in
     
    Timothy Spangler, Aug 16, 2004
    #8
  9. thanks for the input everyone, I learn every time people get into how lisp tracks what is defined...

    James Maeding <>
    |>I just thought this might be useful...
    |>I hate the task of going through lisps and making a list of the variables, then adding them after the / in the defun.
    |>
    |>So I got a seat of LispLink from http://www.caelink.com/lisplink.htm
    |>No I do not work for them.
    |>
    |>They have a super feature where you highlight the function name and pick a button.
    |>It brings up a dialog with a list of the vars, you choose which ones to add to the loaclized list (i.e. after the / in
    |>the defun)
    |>It adds them and the task is done. Super slick.
    |>
    |>So the fast way to use this is to open LispLink and open a blank file and save it.
    |>Then when you bring up the prog, it brings up that blank lisp.
    |>You paste in your code and run the localizer. Then copy the code back to the vlisp editor or wherever.
    |>
    |>Its worth the $30 or whatever the price is.
    |>Curiuos to see if others have slicker tools for this.
    |>James Maeding
    |>Civil Engineer/Programmer

    James Maeding
    Civil Engineer/Programmer
     
    James Maeding, Aug 16, 2004
    #9
  10. James Maeding

    BTO Guest

    i use
    ideclare a free DOS tools from Rollin Laird

    but I will try BillZ method.

    Bruno Toniutti
     
    BTO, Aug 20, 2004
    #10
  11. James Maeding

    BTO Guest

    Thx, I will try.

    Bruno Toniutti
     
    BTO, Aug 20, 2004
    #11
  12. James Maeding

    BillZ Guest

    BTO,

    According to the other posts:
    I would suppose that the Vlide is the best way if you use that interface already.

    The only reason I still use the method that I posted, is that I am just too busy/lazy right now to learn the Vlide interface.
    It has already taken me much time to convert a lot of my old programs from r14 vanilla to r2005 Vlisp.
    I wanted to learn Vlisp so that was my first priority.
    I plan on learning Vlide as time permits but for now rely on my "proven" methods that I don't have to take time to learn about.

    Bill
     
    BillZ, Aug 20, 2004
    #12
  13. James Maeding

    BTO Guest

    According to the other posts:
    too busy/lazy right now to learn the Vlide interface.
    methods that I don't have to take time to learn about.
    Bill,

    sure Vlide is best way, but I prefer notepad :),
    I think that I don't have enough large project to find an interest with
    Vlide.

    I modified your lsp to get a more quickly result, and I prefer to get a
    text.
    Finally for me :


    (setq atoms_list_start T)
    (setq atoms_list_end T)
    (setq variables_txt "")
    (setq atoms_list_start
    (vl-remove-if
    '(lambda (x)
    (or
    (= (substr x 1 2 ) "C:")
    (= (substr x 1 5 ) ":VLR-")
    (= (substr x 1 3 ) "VLA")
    (= (substr x 1 4 ) "ACET")
    )
    )
    (atoms-family 1)
    )
    )

    (setq atoms_list_end
    (vl-remove-if
    '(lambda (x)
    (or
    (= (substr x 1 2 ) "C:" )
    (= (substr x 1 5 ) ":VLR-" )
    (= (substr x 1 3 ) "VLA" )
    (= (substr x 1 4 ) "ACET")
    (= x "*LAST-VALUE*" )
    )
    )
    (atoms-family 1)
    )
    )

    (foreach tmp atoms_list_end
    (if (not (member tmp atoms_list_start ))
    (setq variables_txt (strcat variables_txt tmp " "))
    )
    )
    (princ variables_txt )
    (setq ID_file (open "C:/Traitement/ListeVariables.txt" "w"))
    (princ variables_txt ID_file)
    (close ID_file )
    (startapp "notepad" "C:/Traitement/ListeVariables.txt")

    thanks for your starting point

    Bruno Toniutti
     
    BTO, Aug 23, 2004
    #13
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.